iOS Development UIButton Detailed

Source: Internet
Author: User

This creates a rounded rectangle button UIButton *button1 = [UIButton buttonwithtype:uibuttontyperoundedrect]; The following 6 kinds of button types can be defined,//typedef enum {//Uibuttontypecustom = 0, custom style//uibuttontyperounded Rect, rounded rectangle//uibuttontypedetaildisclosure, Blue small arrow button, mainly to do detailed description with//Uibuttontypeinfolight, Bright         Color exclamation point//Uibuttontypeinfodark, dark exclamation point//Uibuttontypecontactadd, Cross plus button//} Uibuttontype;        The position of the given button on the view Button1.frame = CGRectMake (20, 20, 280, 20);        Button background color button1.backgroundcolor = [Uicolor Clearcolor];        Set button fill picture//[button1 setimage:[uiimage imagenamed:@ "Btng.png"] forstate:uicontrolstatenormal];        Set button title [Button1 settitle:@ "click" Forstate:uicontrolstatenormal]; /* Forstate: The function of this parameter is to define the text of the button or the picture in which state will appear *////The following are several states//enum {//UIControlStateNormal = 0, general status Show//uicontrolstatehighlighted = 1 << 0, highlight State displayNow//uicontrolstatedisabled = 1 << 1, the disabled state will only show//uicontrolstateselected = 1 << 2, Checked status//Uicontrolstateapplication = 0x00ff0000 when application flag//Uicontrolstatereser        ved = 0xff000000 is reserved for the internal frame and can be used regardless of his//};    /* * By default, when the button is highlighted, the color of the image will be painted darker, if this property below is set to NO, * then this function can be removed * * button1.adjustsimagewhenhighlighted = NO;    /* As in the above case, by default, when the button is disabled, the image will be drawn darker, set NO to cancel the setting */button1.adjustsimagewhendisabled = NO;        /* This property is set to YES in the state, the button will glow */button1.showstouchwhenhighlighted = yes;     /* Add an event to the button, there are a number of events, I will open a separate blog to introduce them, the following time means to press the button, and the finger off the screen when the event triggered, and the Web as the Click event. After triggering this event, execute Butclick: This method, addtarget:self, means that this method can also pass in the pointer of another class in this class */[Button1 addtarget:self Action: @selector (BUTC         Lick:) forcontrolevents:uicontroleventtouchupinside];

Settings for buttons in normal and highlighted colors

[_button1 Settitlecolor:[uicolor Yellowcolor] forstate:uicontrolstatehighlighted]; When the button is pressed down, the whole button will turn yellow.

[_button1 settitlecolor:[uicolor Bluecolor] forstate:uicontrolstatenormal];//button in normal state, the caption text on the button is set to Blue



Display Controls [Self.view Addsubview:button1];

iOS Development UIButton Detailed

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.