視窗與視圖的基本概念

來源:互聯網
上載者:User

標籤:

一、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);

 

 

視窗與視圖的基本概念

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.