UIButton Internal Introduction

Source: Internet
Author: User

**
Set content distance from BTN border
**/
Btn.contentedgeinsets = uiedgeinsetsmake (0, 0, 0, 0);

/** label and ImageView as a whole
For example, placing the ImageView behind a label requires calculating the position of the ImageView relative to the label and the distance from the other side.
Popularly said by default the ImageView in the left Titlelabel on the right
Imageedgeinsets left Contrast position no button to border right contrast with his next label
Titlelabeledgeinsets is the same as image
The following code swaps image and label for left and right
**/

[Btn Setimageedgeinsets:uiedgeinsetsmake (0,btn.titlelabel.frame.size.width, 0,- Btn.titlelabel.frame.size.width-btn.imageview.frame.size.width)];

[Btn settitleedgeinsets:uiedgeinsetsmake (0, 0, 0,cgrectgetwidth (btn.imageView.frame))];

This method is more cumbersome to calculate than to directly customize the button to override the Layoutsubviews method directly set the image lable frame to achieve the effect

NOTE: [Super Layoutsubviews]


/**
Reversestitleshadowwhenhighlighted to set whether the shadow is highlighted when the caption is highlighted
Adjustsimagewhenhighlighted the default is yes. If so, when the image is highlighted (pressed)
Adjustsimagewhendisabled the default is yes. If yes, disabled when image is disabled
Showstouchwhenhighlighted is not by default. If yes, displays a simple feedback (currently a glow), while highlighting
**/

btn.reversestitleshadowwhenhighlighted = NO;
btn.showstouchwhenhighlighted = YES;


Set Shadow Color
[btn Settitleshadowcolor:[uicolor Redcolor] forstate:uicontrolstatenormal];
[btn Settitleshadowcolor:[uicolor Greencolor] forstate:uicontrolstatehighlighted];


Attributedstring Header Settings
Nsmutabledictionary * dic = [[Nsmutabledictionary alloc]init];
[dic Setobject:[uicolor Redcolor] forkey:nsbackgroundcolorattributename];
nsattributedstring * aStr = [[nsattributedstring alloc]initwithstring:@ "33333" attributes:dic];
[Btn Setattributedtitle:astr Forstate:uicontrolstatenormal];


/**
Gets the property value for the corresponding state
-(Nullable Uicolor *) Titlecolorforstate: (uicontrolstate) state
-(Nullable Uicolor *) Titleshadowcolorforstate: (uicontrolstate) state
-(Nullable UIImage *) Imageforstate: (uicontrolstate) state
-(Nullable UIImage *) Backgroundimageforstate: (uicontrolstate) state
-(Nullable nsattributedstring *) Attributedtitleforstate: (uicontrolstate) state
**/

/*
In subclasses you can overload the following methods, which return the CGRect structure, indicating the bounds of each component of the button.

Note: Do not call these methods directly, these methods are what you write to the system call.
-(CGRect) Backgroundrectforbounds: (cgrect) bounds set background border
-(CGRect) Contentrectforbounds: (cgrect) bounds developing content boundaries
-(CGRect) Titlerectforcontentrect: (cgrect) contentrect text title border
-(CGRect) Imagerectforcontentrect: (cgrect) contentrect Button Image border
*/

UIButton Internal Introduction

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.