UIButton titleedgeinsets and Imageedgeinsets in iOS

Source: Internet
Author: User

By default, there is no space between the UIButton ImageView and Titlelabel, and two is centered as a whole.

The Titleedgeinsets and imageedgeinsets of the button are not based on the left and right margins of the buttons, but are determined by the current position of the Titlelabel and ImageView.

But in the process of testing, we find problems, such as

CGFloat topMargin = 50;
Self.btnTest.imageEdgeInsets = Uiedgeinsetsmake (topMargin000);

The ImageView position of the button after the operation of our code should be moved down by 50 relative to the previous position, but this is not the case, after several tests (TopMargin takes multiple values), the button's ImageView downward offset (in the state before ImageView ) is always the amount of TOPMARGIN/2.

(This is so strange ...) Finally after thinking ... ^_^ ~, since imageedgeinsets and titleedgeinsets are not relative to the button margin, they are offset relative to the original position. But Uiedgeinsetsmake has four parameters, Top,left,button and right, and the control cannot move up and down at the same time, or move to the left.

Take the following example:

Self.btnTest.imageEdgeInsets = Uiedgeinsetsmake (TopMargin, LeftMargin, Buttommargin, RightMargin);

At this point the offset of the ImageView relative to the original is:

x = (leftmargin-rightmargin)/2;

y = (topmargin-buttommargin)/2;

(measured).

UIButton titleedgeinsets and Imageedgeinsets in iOS

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.