UIButton Father Class Uicontrol
1) Create
UIButton *btn1 = [UIButton buttonwithtype:uibuttontyperoundedrect];
Style has the following
typedef enum {
Uibuttontypecustom = 0,//custom, no style
Uibuttontyperoundedrect,//white rounded rectangle, similar preference table cell or Address Book Card
Uibuttontypedetaildisclosure,//Blue disclosure button, can be placed next to any text
Uibuttontypeinfolight,//widgets use small circle info buttons that can be placed next to any text
Uibuttontypeinfodark,//Dark Circle Info button used on white background
Uibuttontypecontactadd,//Blue plus (+) button, can be placed next to any text
} Uibuttontype;
2) Setting properties
1.Frame Properties
CGRect btn2frame = CGRectMake (10.0, 10.0, 60.0, 44.0);
Btn1.frame =btn2frame;
2. Properties
For any button in a particular state, you can set the button caption for the button in that state. You can set it with the Settitle method:
[Btn1 settitle:@ "BTN1" forstate:uicontrolstatenormal];
You can also set a graph for a certain state of the button. You can use SetImage:
[Btn1 setimage:[uiimage imagenamed:@ "pic"] forstate:uicontrolstatenormal];
In addition, you can set the color and shadow of the caption for each button state, as well as the background of the button. Methods Settitlecolor and Settitleshadowcolor all require a Uicolor object to do the argument:
[Btn1 Settitlecolor:[uicolor Redcolor] forstate:uicontrolstatenormal]; Set the title color
[Btn1 Settitleshadowcolor:[uicolor Graycolor] forstate:uicontrolstatenormal]; Shadow
[Btn1 setbackgroundimage:[uiimage imagenamed:@ "PIC"] forstate:uicontrolstatehighlighted]; Background image
The above methods refer to common parameter forstate. This parameter determines the state in which the title, image, or other property will appear. You can programmatically make the button change in which state
enum {
uicontrolstatenormal = 0, //normal  &NBSP
uicontrolstatehighlighted = 1 << 0 // Highlight
; uicontrolstatedisabled = 1 << 1, //disable
uicontrolstateselected &nbs P = 1 << 2 //Check &NBSP;
uicontrolstateapplication = 0x00ff0000, //When application flags are used &NBSP
uicontrolstatereserved = 0xff000000 &NBSP ;// reserved for internal frames;
};
typedef nsuinteger uicontrolstate;
You just have to master the first four states.
When the button is highlighted or disabled, the UIButton class can adjust its appearance, and the following properties allow you to fine-tune the appearance of the button as needed:
adjustsimagewhenhighlighted
By default, when the button is disabled, the image is painted darker. To disable this feature, set this property to No:
btn1.adjustsimagewhenhighlighted = NO;
Adjustsimagewhendisabled
By default, when the button is disabled, the image will be painted in a lighter color. To disable this feature, set this property to No:
btn1.adjustsimagewhendisabled = NO;
showstouchwhenhighlighted
This property is set to Yes to make the button glow when pressed. This can be used for informational buttons or some important buttons:
btn1.showstouchwhenhighlighted = YES;
3. Display controls
Display the control as always simple:
[Self.view ADDSUBVIEW:BTN1];
4. Overriding the drawing behavior
You can customize your own button class by using the Sub-type button. In subclasses you can overload the following methods, which return the CGRect structure, indicating the bounds of each component of the button.
Note: Do not call these methods directly, these are the methods you write to the system call
Backgroundrectforbounds//Specify background bounds
Contentrectforbounds//Specify content boundaries
Titlerectforcontentrect//Specify text caption boundaries
Imagerectforcontentrect//Specify button image bounds
5. Add an action
What's the button for? Used to excite an action or event. Then we're going to add an action for him, as Uicontrol says:
[Btn1 addtarget:self Action: @selector (btnpressed:) forcontrolevents:uicontroleventtouchupinside];
View about Uicontrolevent to parent class Uicontrol
-(void) btnpressed: (ID) sender{//sender is the button itself.
uibutton* btn = (uibutton*) sender;
Start writing your own moves.
}
Uibutton-ios Development