Basic view of iOS development--uibutton

Source: Internet
Author: User

A button is the most common UI control that inherits the Uicontrol base class, which, by default, belongs to the active control, which interacts with the user and fires the appropriate event-handling method.

The following examples are several commonly used button setup methods:


viewcontroller.m//uibuttondemo////Created by Apple on 16/5/10.//copyright©2016 year. All rights reserved.//#import "ViewController.h" @interface Viewcontroller () @end @implementation viewcontroller-(void        ) Viewdidload {[Super viewdidload];    uilabel* label = [[UILabel alloc] initwithframe:cgrectmake (100, 100, 300, 50)];    Label.text = @ "please click button";    Sets the label of the label so that the label can be used later to get the label [Label SETTAG:100];        [Self.view Addsubview:label]; /**//uibutton type Uibuttontypecustom custom style Uibuttontypesystem standard type uibuttontypedetaildisclosure blue arrow Head button, mainly to do a detailed description with uibuttontypeinfolight color exclamation mark Uibuttontypeinfodark Dark exclamation mark Uibuttontypecontactadd Cross plus button UIButton Typeroundedrect = Uibuttontypesystem,//Deprecated, use Uibuttontypesystem instead */uibutton* BTN = [UIButton    Buttonwithtype:uibuttontypecontactadd];    Btn.frame = CGRectMake (20,200,100,50);            [Self.view ADDSUBVIEW:BTN]; Type of Uibuttontypesystem standard uibutton* BTN2 = [UIButton Buttonwithtype:uibuttontypesystem];    Btn2.frame = CGRectMake (100,200,100,50); /** uicontrolstatenormal normal state appearance uicontrolstatehighlighted highlighting state shows uicontrolstatedisabled disabled state will appear Uicontro lstateselected checked Status Uicontrolstateapplication when the application flag uicontrolstatereserved temporarily without the text on the//Settings button and the default state [    BTN2 settitle:@ "button" forstate:uicontrolstatenormal];    Point state [Btn2 settitle:@ "Button2" forstate:uicontrolstatehighlighted];            [Self.view ADDSUBVIEW:BTN2];    Type of Uibuttontypesystem standard uibutton* btn3 = [UIButton Buttonwithtype:uibuttontypesystem];    Btn3.frame = CGRectMake (200,200,100,50);    Create a UIImage uiimage* img = [UIImage imagenamed:@ "Button.png"];    Set background Image [Btn3 setbackgroundimage:img forstate:uicontrolstatenormal];    Set the text on the button [btn3 settitle:@ "submit" forstate:uicontrolstatenormal];    Sets the color of the text on the button [Btn3 settitlecolor:[uicolor blackcolor] forstate:uicontrolstatenormal]; [Self.view Addsubview:btn3];    Register button Event [Btn3 addtarget:self Action: @selector (OnClick:) forcontrolevents:uicontroleventtouchupinside];        }-(void) OnClick: (ID) sender{uilabel* label = (uilabel*) [Self.view viewwithtag:100]; Label.text = @ "button event is activated";} @end

As follows:

After pressing the "Submit" button:

Basic view of iOS development--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.