Basic use of IOS UIButton

Source: Internet
Author: User

The basic use of UIButton, usually with so much, the other encountered in the addition

// instancing 2 methods

UIButton *btn1 = [[UIButton alloc] init];

UIButton *btn = [UIButton buttonwithtype:uibuttontypecustom];

// coordinates and size

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

// background color

Btn.backgroundcolor = [Uicolor Redcolor];

// Set Font

[Btn settitle:@ "UIButton" forstate:uicontrolstatenormal];

// set Font color

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

// Set the radian of the layer

Btn.layer.cornerRadius = 50.0f;

// The extra layer is hidden

Btn.layer.masksToBounds = YES;

// Set the width of the layer

Btn.layer.borderWidth = 1.0f;

// Set the color of the layer

Btn.layer.borderColor = [[Uicolor Yellowcolor]cgcolor];

// Mark

Btn. Titlelabel. tag = +;

// Set the size of the text

Btn.titleLabel.font = [Uifont systemfontofsize:12.0f];

// text bold

Btn.titleLabel.font = [Uifont boldsystemfontofsize:20];

// Set Picture

[Btn setimage:[uiimage imagenamed:@ "1.png"] forstate:uicontrolstatenormal];

// set background picture

[Btn setbackgroundimage:[uiimage imagenamed:@ "1.png"] forstate:uicontrolstatenormal];

// Set Transparency

[Btn setalpha:0.5f];

// whether to choose

[Btn setselected:YES];

// whether hidden

[Btn sethidden:NO];

// whether to highlight

[Btn Sethighlighted:yes];

// is it possible to touch

[Btn setenabled:YES];

// set whether to interact with things

[Btn Setuserinteractionenabled:yes];

// Set the offset of text

[Btn settitleedgeinsets:uiedgeinsetsmake (0, 0, 0, 0)];

// Set the offset of the picture

[Btn setimageedgeinsets:uiedgeinsetsmake (0, 0, 0, 0)];

// Vertical

[Btn Setcontentverticalalignment:uicontrolcontentverticalalignmentcenter];

// level

[Btn Setcontenthorizontalalignment:uicontrolcontenthorizontalalignmentcenter];

// Text Center

Btn.titleLabel.textAlignment = Nstextalignmentcenter;

// Set Center coordinates

[Btn Setcenter:cgpointmake (100, 100)];

// Set Text shadow color

[btn Settitleshadowcolor:[uicolor Graycolor] forstate:uicontrolstatenormal];

// Text Glow

[Btn Setshowstouchwhenhighlighted:yes];

// Click events

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

// Join the View

[Self.view ADDSUBVIEW:BTN];


This article is from the "11204872" blog, please be sure to keep this source http://11214872.blog.51cto.com/11204872/1744047

Basic use of 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.