UIButton
Essential controls in iOS development, this article lists commonly used properties and methods (note that the Xcode version is 7.2)
1. Set the type of the button
+ (Instancetype) Buttonwithtype: (Uibuttontype) ButtonType;
This is a class method that returns directly to a UIButton object.
Statement: UIButton *btn=[uibutton Buttonwithtype:uibuttontypecustom];
Parameter is an enumeration type that represents
Uibuttontypecustom,//custom type
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7A/FE/wKiom1bEXMSTEzTBAAAOQaC2u0E936.png "title=" no Type " alt= "Wkiom1bexmsteztbaaaoqac2u0e936.png"/>
Uibuttontypesystem Ns_enum_available_ios (7_0), ///Ns_enum_available_ios(7_0), which means it is not available after IOS7.0, system default type
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7A/FE/wKioL1bEXnDgbB48AAAPGimK5QY361.png "title=" System type " alt= "Wkiol1bexndgbb48aaapgimk5qy361.png"/>
uibuttontypedetaildisclosure,//, just explain it.
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7A/FE/wKioL1bEYA-gFIfyAAAQG4XazPc075.png "title=" explanation " alt= "Wkiol1beya-gfifyaaaqg4xazpc075.png"/>
uibuttontypeinfolight,//Bright exclamation mark
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7A/FE/wKioL1bEYOnCl9aEAAAQncCp9y4151.png "title=" Bright "alt = "Wkiol1beyoncl9aeaaaqnccp9y4151.png"/>
uibuttontypeinfodark,//Dark Exclamation
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/7A/FE/wKiom1bEYMrisjEfAAAQEHtNFts998.png "title=" Dark "alt = "Wkiom1beymrisjefaaaqehtnfts998.png"/>
uibuttontypecontactadd,//Plus
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7A/FE/wKioL1bEaG_jCHamAAAPh5wh1cw214.png "title=" plus "alt = "Wkiol1beag_jchamaaaph5wh1cw214.png"/>
Uibuttontyperoundedrect = uibuttontypesystem//System Type
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7A/FE/wKiom1bEaFeDt_lFAAAOt293SNA667.png "title=" screen shot 2016-02-17 pm 8.31.43.png "alt=" Wkiom1beafedt_lfaaaot293sna667.png "/>
2. Setting the title
-(void) Settitle: ( Nullable nsstring *) title forstate: (uicontrolstate) state;
statement: [btn settitle:@ "Hello,world" forstate: uicontrolstatenormal];
This is an object method to set the font displayed on the button, the first parameter is to set the actual content, the second parameter is the state of the button, is an enumeration type, respectively, there are
:
uicontrolstatenormal//stateless, as system default state
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7A/FE/wKioL1bEbu7x4N2VAAARayLFXbg616.png "title=" stateless " alt= "Wkiol1bebu7x4n2vaaaraylfxbg616.png"/>
uicontrolstatehighlighted//highlight state, usually used when the user clicks, to distinguish whether clicked
This is when you click, the loose state of your finger disappears and the text disappears.
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7A/FE/wKioL1bEb6jyEF-IAAAUX1PHs5Y943.png "title=" highlight "alt = "Wkiol1beb6jyef-iaaaux1phs5y943.png"/>
uicontrolstatedisabled//disabled state, must be disabled to set
btn. enabled = NO ;, not set invalid
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7A/FE/wKioL1bEcICxppStAAAUX1PHs5Y303.png "title=" Disable "alt = "Wkiol1becicxppstaaaux1phs5y303.png"/>
uicontrolstatefocused Ns_enum_available_ios (9_0)//This is only after IOS9
uicontrolstateapplication//When application flags
uicontrolstatereserved//internal Reserved No tube
3. Setting the background color
Properties BackgroundColor
btn. BackgroundColor =[uicolor redcolor];
4. Setting up a picture
Button has two places to set the picture, one is to set the button directly to the picture will not show the title, the second is the background image can display the title.
Set the button directly to the picture, and the current state
-(void) setimage: ( Nullable UIImage *) image forstate:(uicontrolstate) state;
Background image must also be set to a state, different states can correspond to different background pictures
-(void) setbackgroundimage: ( Nullable UIImage *) image forstate: (uicontrolstate) State
5. Set the font size
btn. Titlelabel . Font =[uifont systemfontofsize:];
6. Set the font color
[btn settitlecolor: [uicolor greencolor] forstate:uicontrolstatenormal];
8. Setting rounded Corners
When the value is normal for a button length or width, it is rounded,
btn. Layer . Cornerradius =50;
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7A/FF/wKiom1bEemGwcKIrAAAVVEzwey8625.png "title=" Fillet "alt = "Wkiom1beemgwckiraaavvezwey8625.png"/>
This article is from the "Red Corner Antelope" blog, please be sure to keep this source http://2254359459.blog.51cto.com/10776102/1742839
The UIButton of ios-oc-basic control