Uiedgeinsets
typedef struct UIEDGEINSETS {
cgfloat top, left, bottom, right;//Specify amount to inset (positive) for each of the Edges. Values can be negative to ' outset '
} uiedgeinsets;
There are three sets of edgeinsets in UIButton: Contentedgeinsets, Titleedgeinsets, imageedgeinsets
@property (nonatomic) uiedgeinsets contentedgeinsets ui_appearance_selector;//default is Uiedgeinsetszero
@ Property (nonatomic) uiedgeinsets titleedgeinsets; Default is Uiedgeinsetszero
@property (nonatomic) BOOL reversestitleshadowwhenhighlighted; Default is NO. If YES, shadow reverses to shift between engrave and emboss appearance
@property (nonatomic) uiedgeinsets Imagee Dgeinsets; Default is Uiedgeinsetszero
Uiedgeinsetsmake
The four parameters inside the
Indicate the distance from the top, left, bottom, and right edges, and the default is zero, title/image in the center of the button
Uikit_static_inline uiedgeinsets Uiedgeinsetsmake (cgfloat top, cgfloat left, CGFloat bottom, cgfloat right) {UIEdgeIns
ETS insets = {top, left, bottom, right};
return insets;
} Self.view.backgroundColor = [Uicolor blackcolor]; UIButton *button = [UIButton buttonwithtype:uibuttontypecustom];//button type button.frame = CGRectMake (100, 100, 90, 90); Frame Button.backgroundcolor = [Uicolor Cyancolor];//button background color//button Setbackgroundimage:[uiimage image
named:@ "Man_64.png"] forstate:uicontrolstatenormal]; There are three settings for edgeinsets in UIButton: Contentedgeinsets, Titleedgeinsets, imageedgeinsets [button setimage:[uiimage imagenamed:@ "IconHome@2x.png"] forstate:uicontrolstatenormal];//add image to button button.imageedgeinsets = Uiedgeinsetsmake (5,13,21,button.titlelabel.bounds.size.width);/Set the position of the image on the button (top, left, bottom bottom,
right) here can write negative, write to 5, then image is like moving 5 pixels [button settitle:@ "Home" forstate:uicontrolstatenormal];//set the button's title Button.titleLabel.font = [Uifont systemFontofsize:16];//title Font Size button.titleLabel.textAlignment = nstextalignmentcenter;//font centered on Title [button Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal];//set title to the General white Font [button settitlecolor:[ Uicolor Graycolor] forstate:uicontrolstatehighlighted];//setting title is the gray font when the button is selected Button.titleedgeinsets = Uiedgeinsetsmake (-button.titlelabel.bounds.size.width-50, 0, 0);/Set the position of title on the button (top, left, bottom bottom, right)//[button setcontentedgeinsets:uiedgeinsetsmake (0, 0, 0)];////button.contenthorizontalalignment = Uicontr olcontenthorizontalalignmentcenter;//sets the contents of the button horizontally centered ... Set content is changed with title and Image [button addtarget:self action: @selector (TAP) forControlEvents:
UIControlEventTouchUpInside];
[Self.view Addsubview:button];
button corresponding event-(void) Tap {NSLog (@ "tap a button"); Uialertview *alertview = [[Uialertview alloc] initwithtitle:@ "Hello" message:@ "Willingseal" delegate:self
cancelbuttontitle:@ "OK" otherbuttontitles:nil];
[Alertview show];}
Effect Chart:
The image I use here is 64*64.
--
That is a button, the background picture of this button are both pictures and text can be, find a graphic to help you should be very realistic ...!!
The above is the article to share the Ios-uibutton (uiedgeinsets)/Set button on the text and the picture up and down vertically center align, I hope you like.