Common uibutton usage

Source: Internet
Author: User

// Uibutton is a control used in IOS to respond to user clicks. It can display text, images, and user interaction.

// Create uibutton, which is generally created using the class method and does not need to be released

// Uibutton is also a subclass of uicontrol

// 1. Create uibutton (class method is generally used)

// 2. Configure uibutton

// 3. Add it to the parent View

// Create uibutton

Uibutton * mybutton = [uibutton buttonwithtype: uibuttontypesystem];

// Configure uibutton

// Mybutton. Frame = [cgrectmake (100,200, 50, 50)];

[Mybutton setframe: cgrectmake (100,200, 80, 60)];

// Set the text to be displayed for uibutton

[Mybutton settitle: @ "login" forstate: uicontrolstatenormal];

// Set the text size

Mybutton. titlelabel. font = [uifont systemfontofsize: 20];

// Specifies the uibutton background color.

// Mybutton. backgroundcolor = [uicolor orangecolor];

// Add a click event to uibutton

[Mybutton addtarget: Self action: @ selector (mybuttonaction) forcontrolevents: uicontroleventtouchupinside];

// Add an image to the button

[Mybutton setbackgroundimage: [uiimage imagenamed: @ "1.jpg"] forstate: uicontrolstatenormal];

[Mybutton setbackgroundimage: [uiimage imagenamed: @ "2.jpg"] forstate: uicontrolstatehighlighted];

// Add an image to the button, center it, instead of using Al

Mybutton. contentmode = uiviewcontentmodecenter;

 

// Add to parent View

[Contentview addsubview: mybutton];

Common uibutton usage

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.