3. IOS Programming UIButton

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.