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