眾里尋他千百度驀然回首,那人卻在,燈火闌珊處。
眾里尋他千百度驀然回首,那人卻在,燈火闌珊處。
UIWindow
//功能:展示UI空間
//分配空間并且初始化設(shè)置UIWindow大小(屏幕大小)
//1.1創(chuàng)建Window對(duì)象并設(shè)置屏幕上顯示大小和位置
//[UIScreen mainScreen].bounds] 獲取主屏幕的大小;
//[UIScreen mainScreen]獲得是一個(gè)單例對(duì)象屏幕的主窗口,初始化并且給了一個(gè)window的原點(diǎn)和大小.
self.window =[[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
//1.2為Window對(duì)象設(shè)置背景顏色,默認(rèn)都是白色的除非特殊要求
self.window.backgroundColor =[UIColor yellowColor];
//1.3window成為主窗口并且顯示出來(lái)
[self.window makeKeyAndVisible];
//1.4創(chuàng)建視圖對(duì)象并且設(shè)置為根視圖控制器
self.window.rootViewController =[UIViewController alloc];
UIView
1.管理內(nèi)容
2.管理子視圖
3.處理事件
4.實(shí)現(xiàn)動(dòng)畫(huà)
知識(shí)點(diǎn)細(xì)節(jié)
- UIView的父類UIResponder
- fram : 相對(duì)于父視圖來(lái)說(shuō),也就是在父視圖中的位置和大小
- bounds: 是相對(duì)于自身的坐標(biāo)系來(lái)說(shuō)
//UIView的常用的一些屬性:
UIView *aview =[[UIView alloc] init];
//背景顏色
aview.backgroundColor =[UIColor blueColor];
//大小位置
aview.frame =CGRectMake(100, 150, 100, 100);
//添加到window上
[self.window addSubview:aview];
// 將aview方到屏幕中心
aview.center = self.window.center;
// hidden,控制視圖的隱藏顯示 NO:顯示 YES:隱藏 默認(rèn)顯示
aview.hidden = NO;
// alpha ,設(shè)置視圖的透明度
aview.alpha =1.0;
// 打印父視圖
NSLog(@"%@",aview.superview);
// 打印子視圖
UIView *bview =[[UIView alloc] init];
bview.backgroundColor =[UIColor greenColor];
bview.frame =CGRectMake(30, 30,50 , 50);
[aview addSubview:bview];
NSLog(@"******%@",aview.subviews);
//tag值
aview.tag =101;
//使用tag值找到視圖
NSLog(@"tag101 = %@",[self.window viewWithTag:101]);
//練習(xí)實(shí)現(xiàn)
**實(shí)現(xiàn)這樣的一個(gè)簡(jiǎn)單的界面**
for (int i=0 ; i < 4; i++)
{
for (int j=0; j<4-i; j++)
{
UIView *tempView =[[UIView alloc]initWithFrame:CGRectMake(100*j, 100*i, 90, 90)];
tempView.backgroundColor =[UIColor colorWithRed:kColor green:kColor blue:kColor alpha:1];
[self.window addSubview:tempView];
}
}