The basic use of UIButton, usually with so much, the other encountered in the addition
// instancing 2 methods
UIButton *btn1 = [[UIButton alloc] init];
UIButton *btn = [UIButton buttonwithtype:uibuttontypecustom];
// coordinates and size
Btn. frame = CGRectMake(+, +, +) ;
// background color
Btn.backgroundcolor = [Uicolor Redcolor];
// Set Font
[Btn settitle:@ "UIButton" forstate:uicontrolstatenormal];
// set Font color
[btn Settitlecolor:[uicolor Graycolor] forstate:uicontrolstatenormal];
// Set the radian of the layer
Btn.layer.cornerRadius = 50.0f;
// The extra layer is hidden
Btn.layer.masksToBounds = YES;
// Set the width of the layer
Btn.layer.borderWidth = 1.0f;
// Set the color of the layer
Btn.layer.borderColor = [[Uicolor Yellowcolor]cgcolor];
// Mark
Btn. Titlelabel. tag = +;
// Set the size of the text
Btn.titleLabel.font = [Uifont systemfontofsize:12.0f];
// text bold
Btn.titleLabel.font = [Uifont boldsystemfontofsize:20];
// Set Picture
[Btn setimage:[uiimage imagenamed:@ "1.png"] forstate:uicontrolstatenormal];
// set background picture
[Btn setbackgroundimage:[uiimage imagenamed:@ "1.png"] forstate:uicontrolstatenormal];
// Set Transparency
[Btn setalpha:0.5f];
// whether to choose
[Btn setselected:YES];
// whether hidden
[Btn sethidden:NO];
// whether to highlight
[Btn Sethighlighted:yes];
// is it possible to touch
[Btn setenabled:YES];
// set whether to interact with things
[Btn Setuserinteractionenabled:yes];
// Set the offset of text
[Btn settitleedgeinsets:uiedgeinsetsmake (0, 0, 0, 0)];
// Set the offset of the picture
[Btn setimageedgeinsets:uiedgeinsetsmake (0, 0, 0, 0)];
// Vertical
[Btn Setcontentverticalalignment:uicontrolcontentverticalalignmentcenter];
// level
[Btn Setcontenthorizontalalignment:uicontrolcontenthorizontalalignmentcenter];
// Text Center
Btn.titleLabel.textAlignment = Nstextalignmentcenter;
// Set Center coordinates
[Btn Setcenter:cgpointmake (100, 100)];
// Set Text shadow color
[btn Settitleshadowcolor:[uicolor Graycolor] forstate:uicontrolstatenormal];
// Text Glow
[Btn Setshowstouchwhenhighlighted:yes];
// Click events
[Btn addtarget:self Action: @selector (Gotoview:) forcontrolevents:uicontroleventtouchupinside];
// Join the View
[Self.view ADDSUBVIEW:BTN];
This article is from the "11204872" blog, please be sure to keep this source http://11214872.blog.51cto.com/11204872/1744047
Basic use of IOS UIButton