Use uiedgeinsetsmaketitle on uibutton to align with the image

Source: Internet
Author: User

Http://blog.csdn.net/yanxiaoqing/article/details/7230660

By default, all the effects that are not set are centered and the button is 150*150.

After using the following settings:

[Self settitleedgeinsets: uiedgeinsetsmake (0.0,-backgroundimag. Size. Width, 0.0, 0.0)];

[Self setimageedgeinsets: uiedgeinsetsmake (0.0, 0.0, 0.0,
-Self. titlelabel. bounds. Size. width)];

If you want to place the title on the top of the image, move the position up to 80 relative to the image.

[Self settitleedgeinsets: uiedgeinsetsmake (-80.0,-backgroundimag. Size. Width, 0.0, 0.0)];

[Self setimageedgeinsets: uiedgeinsetsmake (0.0, 0.0, 0.0,
-Self. titlelabel. bounds. Size. width)];

The effect is as follows:

To sum up, if you set a title or image position in the button separately, uiedgeinsets is calculated relative to the frame of the button (top, left, bottom, right ,), if the problem is described just now, the title is set relative to the frame of the image, and the position of the image is set relative to the location of the titel.

Over!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.