Initialize the button and set the type UIButton *btn = [UIButton buttonwithtype:uibuttontyperoundedrect];//can be defined by the following 6 types of UIButton://typedef enum {//Uibuttontypecustom = 0, self-defined style//uibuttontyperoundedrect, Rounded rectangle//Uibuttonty Pedetaildisclosure, Blue small arrow button, mainly to do specific instructions with//uibuttontypeinfolight, bright exclamation mark//Uibuttontypeinfodark, Dark exclamation point//Uibuttontypecontactadd, Cross plus button//} uibuttontype;//set button size and position btn.frame = CGR Ectmake (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 the role of this parameter is to define the state of the button's text or picture to appear, following several states: enum {//UIControlStateNormal = 0, General status Show//uicontrolstatehighlighted = 1 << 0, Highlight status Show//uicontrolstatedisabled = 1 << 1, The disabled state will only show//uicontrolstateselected = 1 << 2, check status//Uicontrolstateapplication = 0x00ff0000, When the application flags//uicontrolstatereserved = 0xff000000 is reserved for the internal frame, you can set the button text color regardless of his//};//[BTN Settitlecolor:[uico Lor Redcolor] forstate:uicontrolstatenormal];//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 pressed delay in overlay view tableview.delayscontenttouches = no;//Join Click event [BTN Addtarget:self Action: @selector (btnaction:) forcontrolevents:uicontroleventtouchupinside];//display in view button[ TableView addsubview:btn];//button click Event-(void) Btnaction: (ID) sender{//Do something}
This article fixed link: http://www.itechzero.com/ios-development-series-one-uibutton-usage-summary.html. Reprint please indicate the source.
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
iOS in a development series-UIButton Usage Summary