標籤:
一、UIWindow1.UIWindow和UIView的關係
(1)UIWindow是UIView的一個子類,提供視圖的顯示地區;
(2)UIWindow繼承自UIView,包含應用程式的可視地區。
2.UIWindow的建立
//1.擷取螢幕尺寸 UIScreen *screen=[UIScreen mainScreen]; CGRect rect=screen.bounds; //2.建立視窗,並鋪滿整個螢幕 self.window=[[UIWindow alloc] initWithFrame:rect]; //3.給視窗添加背景色 self.window.backgroundColor=[UIColor colorWithRed:1.0 green:1.0 blue:0.0 alpha:1.0]; // self.window.backgroundColor=[UIColor whiteColor]; //4.顯示視窗 [self.window makeKeyAndVisible];
二、iOS座標系統1.建立視圖View
//建立視圖v0,v0作為UIWindow的子視圖 UIView *v0=[[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)]; v0.backgroundColor=[UIColor blueColor]; [self.window addSubview:v0]; //建立視圖v1,v1作為UIWindow的子視圖 UIView *v1=[[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)]; v1.backgroundColor=[UIColor redColor]; [self.window addSubview:v1]; //建立視圖v2,v2作為UIWindow的子視圖 UIView *v2=[[UIView alloc]initWithFrame:CGRectMake(150, 150, 200, 200)]; v2.backgroundColor=[UIColor greenColor]; [self.window addSubview:v2];
2.frame、bounds、center的關係
frame:表示視圖在父視圖的座標系統裡的位置和大小。
bounds:表示視圖在本身的座標系統裡的位置和大小。
center:表示視圖在父視圖的座標系統裡的中點位 置。
註:改變其中一個屬性會影響其它兩個。
v2.frame = CGRectMake(0, 0, 200, 200);// v1.center = CGPointMake(100, 100);// v1.bounds = CGRectMake(0, 0, 200, 200);// v1.frame = CGRectMake(200, 200, 10, 200);
視窗與視圖的基本概念