iOS Development Xcode Learning 003:uibutton Basics

Source: Internet
Author: User

The learning source of this article is: http://study.163.com/course/introduction/1002858003.htm

This project file implements the function:

1. Basic concept of UIButton control

2. How to create UIButton

3, the type of UIButton

4, can display the picture UIButton

The prepared picture can be dragged directly to the project name UIButton

===========================VIEWCONTROLLER.M Script ==============================

Create a normal button function

-(void) Createuirectbutton

{

Create a Btn object that creates a btn based on the type

Round Corner Type

To create a buttonwithtype by using a class method: Class name + method name

uibutton* btn = [UIButton buttonwithtype:uibuttontyperoundedrect];//own memory management

//Set the location of button buttons

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

Set the text content of a button

@parameter

P1: String type, text to display on the button

P2: Sets the status type of text display: UIControlStateNormal, normal state

[btn settitle:@ button] "Forstate:uicontrolstatenormal";

P1: Text to display

P2: Display the status of text: uicontrolstatehighlighted, press State

[btn settitle:@] Button Press "forstate:uicontrolstatehighlighted";

Gray background Color

Btn.backgroundcolor = [Uicolor Graycolor];

//Set the color of text display

//P1: Color

P2: Status

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

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

//Set the style color of the button

[Btn Settintcolor:[uicolor Whitecolor];

//titlelabel:uilabel Controls

Btn.titleLabel.font = [Uifont systemfontofsize:24];

//Add to view and display

[Self.view ADDSUBVIEW:BTN];

}

-(void) createimagebtn

{

//Create a custom type of BTN

uibutton* btnimage = [UIButton buttonwithtype:uibuttontypecustom];

Btnimage.frame = CGRectMake (100, 200, 100, 100);

uiimage* Icon01 = [UIImage imagenamed:@ "btn01.jpg"];

uiimage* icon02 = [UIImage imagenamed:@ "btn02.jpg"];

//Set button picture

//P1: The picture object that is displayed

P2: The state of the control

[Btnimage Setimage:icon01 Forstate:uicontrolstatenormal];

[Btnimage setimage:icon02 forstate:uicontrolstatehighlighted];

[Self.view Addsubview:btnimage];

}

-(void) Viewdidload {

[Super Viewdidload];

Additional setup after loading the view, typically from a nib.

[Self Createuirectbutton];

[Self createimagebtn];

}

Learning Summary:

    • Focus: Attribute usage of UIButton
    • Difficulty: UIButton Display pictures

Source Link Address: Https://pan.baidu.com/s/1yrOLXZZeu9MiOWtMq5-EGA Password: 7t1l

iOS Development Xcode Learning 003:uibutton Basics

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.