iOS學(xué)習(xí)(UI)知識(shí)點(diǎn)整理
一、關(guān)于UIVIew 的介紹
1)概念:UIView 是用于裝載并展示各類(lèi)控件的大容器,是iOS中所有UI控件的基類(lèi)
2)UIView 初始化實(shí)例代碼
1 UIView *view1 = [[UIView alloc] init]; 2 view1.frame = CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height/2); 3 view1.backgroundColor = [UIColor lightGrayColor]; 4 view1.tag = 1000; 5 6 //alpha屬性設(shè)置view的透明度 7 view1.alpha = 0.5; 8 9 //超出部分自動(dòng)隱藏10 view1.clipsToBounds = YES;11 [self.view addSubview:view1];
3)sendSubviewToBack 父視圖可以使用sendSubviewToBack方法將子視圖放在最下層
例如:
1 UIView *view3 = [[UIView alloc] init];2 view3.frame = CGRectMake(45, 45, 240, 260);3 view3.backgroundColor = [UIColor blueColor];4 view3.tag = 1001;5 [view1 addSubview:view3];6 7 //父視圖把某一子視圖放在最下層8 [view1 sendSubviewToBack:view3];
4)bringSubviewToFront 父視圖可以使用sendSubviewToBack方法將子視圖放在最上層
例如:
1 UIView *view2 = [[UIView alloc] init];2 view2.frame = CGRectMake(40, 40, 250, 250);3 view2.backgroundColor = [UIColor blackColor];4 view2.tag = 1001;5 [view1 addSubview:view2];6 7 //父視圖把某一子視圖放在最上層8 [view1 bringSubviewToFront:view2];
5)獲取self.view中所有的子視圖 例如:
1 NSArray *subViews = self.view.subviews;
6)removeFromSuperview 將子視圖從父視圖中移除 例如:
1 [view1 removeFromSuperview];
7) viewWithTag 根據(jù)視圖Tag標(biāo)記獲取視圖 例如:
1 UIView *view = [self.view viewWithTag:1000];
8) hidden 隱藏視圖 例如:
1 view.hidden = YES;
9)因?yàn)樗械腢I控件都繼承自UIVIew 所以根據(jù)控件的Tag標(biāo)記可以使用viewWithTag獲取控件對(duì)象
例如:
1 //1000 為button的Tag標(biāo)記 注意:需要強(qiáng)轉(zhuǎn)一下2 UIButton *button=(UIButton*)[self.view viewWithTag:1000];
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注