Back to Nature, UIButton is a control we use most frequently. Below, some of the common methods of the control are summarized.
UIButton *paystatebtn =[UIButton Buttonwithtype:uibuttontypecustom]; Paystatebtn.frame= CGRectMake ( A,Ten, ScreenWidth- -, A); //Set Font Center orientationPaystatebtn.contenthorizontalalignment =Uicontrolcontenthorizontalalignmentleft; //Set FontPayStateBtn.titleLabel.font = [Uifont systemfontofsize: -]; [Paystatebtn settitle:@"Payment Failure"Forstate:uicontrolstatenormal]; [Paystatebtn settitle:@"Payment Success"forstate:uicontrolstateselected]; [Paystatebtn Settitleedgeinsets:uiedgeinsetsmake (0,3,0,0)]; [Paystatebtn Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal]; [Paystatebtn Settitlecolor:[uicolor colorwithhexstring:color_red] forstate:uicontrolstateselected]; [Paystatebtn setimage:[uiimage imagenamed:@"Failure"] Forstate:uicontrolstatenormal]; [Paystatebtn setimage:[uiimage imagenamed:@"Success"] forstate:uicontrolstateselected]; [Self. View ADDSUBVIEW:PAYSTATEBTN];
The above code, very common, we are looking at the code, has probably known the meaning.
To display when checked, you only need to set: paystatebtn.selected = Yes;
Some of the other commonly used properties
Set non-clickable
[Button Setuserinteractionenabled:no];
Set Center location Point
Btn1.center = Cgpointmake (215);
Set Button style
//There are 6 kinds of button types that can be defined://typedef enum {//uibuttontypecustom = 0, custom style//Uibuttontyperoundedrect, Rounded rectangle//uibuttontypedetaildisclosure, Blue small arrow button, mainly to do detailed instructions with//uibuttontypeinfolight, bright exclamation marks//Uibuttontypeinfodark, Dark exclamation//Uibuttontypecontactadd, Cross plus button//} Uibuttontyp
Other
/*forstate: The function of this parameter is to define how the text or picture of the button will appear in the state .*/ //Here are a few states//Enum {//uicontrolstatenormal = 0, normal state appearance//uicontrolstatehighlighted = 1 << 0, highlight state appears//uicontrolstatedisabled = 1 << 1, disabled status only appears//uicontrolstateselected = 1 << 2, check status//uicontrolstateapplication = 0x00ff0000 When the application is marked//uicontrolstatereserved = 0xff000000 is reserved for the internal frame and can be used regardless of his// }; /** By default, when the button is highlighted, the color of the image will be drawn darker, if this property is set to No, * then this function can be removed*/button1.adjustsimagewhenhighlighted=NO; /*as is the case above, by default, when the button is disabled, the image is drawn deeper, set No to cancel the setting*/button1.adjustsimagewhendisabled=NO; /*When this property is set to Yes, the button will glow when pressed*/button1.showstouchwhenhighlighted=YES; /*to add events to the button, there are a number of events, I will open a separate blog to introduce them, the following time means to press the button, and the finger off the screen when the event triggered by the same as the Click event in the Web. After triggering this event, execute Butclick: This method, addtarget:self, means that this method can also pass pointers to other classes in this class*/[Button1 addtarget:self Action: @selector (Butclick:) forcontrolevents:uicontroleventtouchupinside];
IOS UI Basics -16.0 UIButton