Initialize the button and set the type UIButton *btn = [UIButton buttonwithtype:uibuttontyperoundedrect];//can define the following 6 types of UIButton://typedef enum {//Uibuttontypecustom = 0, custom style//Uibuttontyperoundedrect, Rounded rectangle//Uibuttontypedet Aildisclosure, Blue small arrow button, mainly to do the detailed description with//Uibuttontypeinfolight, bright exclamation mark//Uibuttontypeinfodark, Dark exclamation point//Uibuttontypecontactadd, Cross plus button//} uibuttontype;//Set button size and position btn.frame = CGRectMake (20, 360, 280, 45);//Set button background color Btn.backgroundcolor = [Uicolor colorwithred:254/255.0f green:254/255.0f blue:254/255.0f alpha:1.0f ];//Set button text [btn settitle:@ "Normal" forstate:uicontrolstatenormal]; [Btn settitle:@ "Pressed" forstate:uicontrolstatehighlighted];//forstate This parameter is the role of defining the button text or picture in which state will appear, the following are several states:// enum {//UIControlStateNormal = 0, General status Show//uicontrolstatehighlighted = 1 << 0, Highlight status Show//uicontrolstatedisabled = 1 << 1, disabled status will only show//Uicontrolstateselected = 1 << 2, check status//Uicontrolstateapplication = 0x00ff0000 when application flag//Uicontrol statereserved = 0xff000000 is reserved for internal frame, can be set button text color regardless of his//};//[btn settitlecolor:[uicolor Redcolor] Forstate:uicontrols tatenormal];//Set button text font [Btn.titlelabel Setfont:[uifont systemfontofsize:17]; [Btn.layer setmaskstobounds:yes];//Set button four fillet radius [btn.layer setcornerradius:4.0];//Set button border Width [Btn.layer setborderwidth : 0.5];//Set button border color cgcolorref colorref = Cgcolorcreate (Cgcolorspacecreatedevicergb (), (cgfloat[]) {168/255.0f, 168/ 255.0f, 168/255.0f, 1.0}); [Btn.layer setbordercolor:colorref];//Remove button Press delay in overlay view tableview.delayscontenttouches = no;//Add Click event [btn addTarget: Self action: @selector (btnaction:) forcontrolevents:uicontroleventtouchupinside];//Displays the button in the view [TableView addsubview: btn];//button click Event-(void) Btnaction: (ID) sender{//Do something}
This article fixed link: http://www.itechzero.com/coding/objective-c/ios-development-series-one-uibutton-usage-summary/, reprint please indicate the source.