How to use Ios--uibutton

Source: Internet
Author: User

How to use Ios--uibutton details(2013-08-23 17:20:38)reproduced
Tags: ios uibutton button using detailed it Category: Ios--ui

Common methods of UIButton

UIButton *onebutton = [UIButton buttonwithtype:uibuttontypecustom]; Set button style when initializing

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

Small Circle Information button used by the uibuttontypeinfolight,//widget (widget), which can be placed next to any text

uibuttontypeinfodark,//Dark Circle Info button used on white background

uibuttontypecontactadd,//Blue Plus (+) button, which can be placed next to any text

} Uibuttontype;

Most commonly used

Onebutton.frame = CGRectMake (10, 10, 300, 30); Setting the location and size of the Onebutton

Onebutton.backgroundcolor = [Uicolor Bluecolor]; Set Onebutton background color

Onebutton.alpha = 0.8; Set the Onebutton transparency range between 0.0 and 1.0

[Onebutton settitle:@ "I am a UIButton" forstate:uicontrolstatenormal]; Set what text to display in what state

[Onebutton Settitlecolor:[uicolor Redcolor] forstate:uicontrolstatenormal];//set what state of the font what color

[Onebutton setbackgroundimage:[uiimage imagenamed:@ "Image.jpg"]forstate:uicontrolstatenormal]; Set the background image to display in what state

The above methods all refer to the 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 that state

enum {

UIControlStateNormal = 0,//Normal

uicontrolstatehighlighted = 1 << 0,//Highlight

uicontrolstatedisabled = 1 << 1,//disable

uicontrolstateselected = 1 << 2,//Selected

Uicontrolstateapplication = 0x00ff0000,//When application flags are used

uicontrolstatereserved = 0xff000000//reserved for internal frame

//    };

Onebutton.tag = 10001; Settings tab, which button is used for easy click, commonly used in the delegate method

[Onebutton.titlelabel Setfont:[uifont systemfontofsize:25.0f]; Set the size of text

onebutton.adjustsimagewhendisabled = NO; Fine-tune the button. When the button is disabled, the image will be painted darker some default is yes, prohibit set to No

onebutton.adjustsimagewhenhighlighted = NO; Fine-tune the button. When the button is highlighted, the image will be drawn darker some default is yes, prohibit set to No

onebutton.showstouchwhenhighlighted = YES; Set the lighting effect when you click

Add a response event to a button

[Onebutton addtarget:self Action: @selector (onebuttontouchupinside:) forcontrolevents:uicontroleventtouchupinside] Onebuttontouchupinside: Method is executed when the button is pressed. This method is custom and needs to be written by itself. parameter is (UIButton *) type

Add to view

[Self.view Addsubview:onebutton];

How to use Ios--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.