標籤:loading ima 添加 風格 檔案 ios view ted stat
此文學習來源為:http://study.163.com/course/introduction/1002858003.htm
此工程檔案實現功能:
1、UIButton的控制項基本概念
2、UIButton的建立方法
3、UIButton的類型
4、可顯示圖片的UIButton
可將準備好的圖片直接拖到工程名字UIButton下
===========================ViewController.m指令碼==============================
//建立普通按鈕函數
-(void)CreateUIRectButton
{
//建立一個btn對象,根據類型來建立btn
//圓角類型
//通過類方法來建立buttonWithType:類名 + 方法名
UIButton* btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];//自己管理記憶體
//設定button按鈕的位置
btn.frame = CGRectMake(100, 100, 100, 40);
//設定按鈕的文字內容
//@parameter
//P1:字串類型,顯示到按鈕上的文字
//P2:設定文字顯示的狀態類型:UIControlStateNormal,正常狀態
[btn setTitle:@"按鈕01" forState:UIControlStateNormal];
//P1:顯示的文字
//P2:顯示文字的狀態:UIControlStateHighlighted,按下狀態
[btn setTitle:@"按鈕按下" forState:UIControlStateHighlighted];
//灰色背景顏色
btn.backgroundColor = [UIColor grayColor];
//設定文字顯示的顏色
//P1:顏色
//P2:狀態
//[btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];
//設定按鈕的風格顏色
[btn setTintColor:[UIColor whiteColor]];
//titleLabel:UILabel控制項
btn.titleLabel.font = [UIFont systemFontOfSize:24];
//添加到視圖中並顯示
[self.view addSubview:btn];
}
-(void)createImageBtn
{
//建立一個自訂類型的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"];
//設定按鈕圖片
//P1:顯示的圖片對象
//P2:控制項的狀態
[btnImage setImage:icon01 forState:UIControlStateNormal];
[btnImage setImage:icon02 forState:UIControlStateHighlighted];
[self.view addSubview:btnImage];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self CreateUIRectButton];
[self createImageBtn];
}
學習總結:
- 重點:UIButton的屬性用法
- 痛點:UIButton顯示圖片
源碼連結地址:https://pan.baidu.com/s/1yrOLXZZeu9MiOWtMq5-EGA 密碼:7t1l
IOS開發之XCode學習003:UIButton基礎