Before the configuration & creation is done, start the first step in application development: understand the application components. For example, buttons, text boxes, etc... This article introduces the button first.
1. Create a button
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions { Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]]; Self.window.backgroundColor = [Uicolor Whitecolor]; Uiviewcontroller *viewcontroller = [Uiviewcontroller alloc]; Self.window.rootViewController = Viewcontroller; UIView *rootview = [[UIView alloc] initwithframe:[[uiscreen mainscreen] bounds]]; Viewcontroller.view = Rootview; /** * Create UIButton///Create button, you must use Buttonwithtype: To create, like above UIView or other can be used alloc UIButton *button = [Uibutt On Buttonwithtype:uibuttontypesystem]; Sets the position, width, and height of the button. Parameters: X-axis, y-axis, width, height button.frame = cgrectmake (100, 100, 100, 30); Sets the background color of the button Button.backgroundcolor = [Uicolor Yellowcolor]; You must set the text of the button in this way and set its state. Cannot use Button.titlelabel to set text, do not display [button settitle:@ "I am button" forstate:uicontrolstatenormal]; Add a button to the view control display [Rootview Addsubview:button]; [Self.window Makekeyandvisible]; return YES;}
1) Uibuttontype has the following enumeration values:
Uibuttontypecustom-----Custom
Uibuttontypesystem-----Standard system default
Uibuttontypedetaildisclosure----- Display the current list details, display I
Uibuttontypeinfolight----- Display a short message showing I
Uibuttontypeinfodark----- Display a short message showing I
Uibuttontypecontactadd----- Add information, display +
2) Uicontrolstate has the following enumeration values:
UIControlStateNormal----- Default
uicontrolstatehighlighted----- Highlight
uicontrolstatedisabled----- Disabled
uicontrolstateselected----- Selected
The other properties of the button can only be viewed by looking at the document, some piecemeal I will not write it out.
Operation Result:
2. Bind an Event
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {... //Use AddTarget:action:forControlEvents: method to bind an event [Button addtarget:self action: @selector (Click:) forcontrolevents:uicontroleventtouchupinside]; ...} Binding the method to be implemented click:-(void) Click: (ID) sender{ NSLog (@ "I am a button");}
The effect of clicking the button after running:
1) Uicontrolevent has the following enumeration values:
Uicontroleventtouchdown
Uicontroleventtouchdownrepeat
Uicontroleventtouchdraginside
Uicontroleventtouchdragoutside
Uicontroleventtouchdragenter
Uicontroleventtouchdragexit
UIControlEventTouchUpInside
Uicontroleventtouchupoutside
Uicontroleventtouchcancel
Uicontroleventvaluechanged
Uicontroleventeditingdidbegin
Uicontroleventeditingchanged
Uicontroleventeditingdidend
Uicontroleventeditingdidendonexit
Uicontroleventalltouchevents
Uicontroleventalleditingevents
Uicontroleventapplicationreserved
Uicontroleventsystemreserved (Application use)
Uicontroleventallevents (framework use)
The basic part, a brief introduction on the line, later encountered related to the other way to explain how to use.
Chapter Three, End!
This article is original, reproduced please specify the source, prohibited for commercial use. Thank you!
3. IOS Programming UIButton