iOS Learning--uibutton Common methods (20150122)

Source: Internet
Author: User

1. Create a custom button

UIButton *btn = [UIButton buttonwithtype:uibuttontypecustom];

2. Add a button

[Self.view ADDSUBVIEW:BTN];

3. Setting the position and size of the button

Btn.frame = CGRectMake (100, 100, 100, 100);

4. Tap the button click (The Btnclick method of self is called when the button is clicked)

[Btn addtarget:self Action: @selector (Btnclick) forcontrolevents:uicontroleventtouchupinside];

5. Set the properties of the button in the default state

5.1. Background of the default state

[Btn setbackgroundimage:[uiimage imagenamed:@ "btn_01"] forstate:uicontrolstatenormal];

5.2. Default state of text

[Btn settitle:@ "point me," forstate:uicontrolstatenormal];

5.3. The text color of the default state

[btn Settitlecolor:[uicolor Redcolor] forstate:uicontrolstatenormal];

6. Set the properties of the button in the highlighted state

6.1. Background of the highlighted state

[Btn setbackgroundimage:[uiimage imagenamed:@ "btn_02"] forstate:uicontrolstatehighlighted];

6.2. Text in highlighted state

[Btn settitle:@ "Touch me what to do" forstate:uicontrolstatehighlighted];

6.3. The text color of the highlighted state

[btn Settitlecolor:[uicolor Bluecolor] forstate:uicontrolstatehighlighted];

iOS Learning--uibutton Common methods (20150122)

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.