UIView
UIView表示屏幕上的一塊矩形區(qū)域誉裆,它在App中占有絕對(duì)重要的地位罕容,因?yàn)镮OS中幾乎所有可視化控件都是UIView的子類。負(fù)責(zé)渲染區(qū)域的內(nèi)容高帖,并且響應(yīng)該區(qū)域內(nèi)發(fā)生的觸摸事件
初始化方式:
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
即初始化一個(gè)大小為50*50 xy軸坐標(biāo)為(0,0)的view
常用方法:
添加子控件: ??
?[UIView addSubview:Subview]
移除子控件:
[Subview removeFromSuperview]
獲取當(dāng)前所有的子控件(返回值為nsarray類型):
[self.view subviews];
UIView的常用動(dòng)畫方法:
1.UIView animateWithDuration:<#(NSTimeInterval)#> animations:<#^(void)animations#>
NSTimeInterval:動(dòng)畫時(shí)間
^(void)animations:需要執(zhí)行動(dòng)畫的block代碼塊
2.UIView animateWithDuration:<#(NSTimeInterval)#> animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>
NSTimeInterval:動(dòng)畫時(shí)間
^(void)animations:需要執(zhí)行動(dòng)畫的block代碼塊
^(BOOL finished)completion:動(dòng)畫播放完后需要執(zhí)行的block代碼塊
注意:只有顏色缰儿,frame,alpha的改變才會(huì)有動(dòng)畫效果
UIButton
初始化方式:
UIButton *button=[UIButton buttonWithType:<#(UIButtonType)#>]
UIButtonType:為枚舉類型散址,包括:UIButtonTypeCustom(自定義類型)乖阵,UIButtonTypeSystem(系統(tǒng)類型)
常用方法
設(shè)置背景顏色
[button setBackgroundColor:]
設(shè)置背景圖片(根據(jù)不同的狀態(tài))
? [button setImage:<#(nullable UIImage *)#> forState:<#(UIControlState)#>]
?[ button setBackgroundImage:<#(nullable UIImage *)#> forState:<#(UIControlState)#>]
以上兩個(gè)方法都可以為button設(shè)置背景圖片,不同的是预麸,用backgroundImage瞪浸,會(huì)將圖片按照一倍圖的方式進(jìn)行填充,且此時(shí)設(shè)置button的title可見吏祸,setImage就直接當(dāng)做button的content,會(huì)按照?qǐng)D片的實(shí)際倍數(shù)進(jìn)行填充对蒲,此時(shí)設(shè)置title不可見。
button添加點(diǎn)擊事件
[button addTarget:<#(nullable id)#> action:<#(nonnull SEL)#> forControlEvents:<#(UIControlEvents)#>]
target:是指需要哪個(gè)實(shí)例來執(zhí)行觸發(fā)方法
action:是指需要執(zhí)行的方法
ControlEvents(枚舉):是指響應(yīng)哪種手勢(shì)