UIView UIWindow,uiviewuiwindow

來源:互聯網
上載者:User

UIView UIWindow,uiviewuiwindow
一、window 簡介

window 是視窗,每個app都要藉助window將內容展現給使用者看。
在iOS中,通常使用UIWIndow類來表示視窗,通常一個應用程式只建立一個UIWIndow對象。

二、建立UIWindow
// 1.建立window對象    self.window = [[[UIWindow alloc] init] autorelease];    // 2.設定window的位置和大小,(window大小和螢幕一樣大,位置為0,0)    self.window.frame = [UIScreen mainScreen].bounds;    // 3. 設定背景顏色    self.window.backgroundColor = [UIColor purpleColor];    // 4. 使window 可以使用    [self.window makeKeyAndVisible];
三、建立UIView
*  // 1. 建立UIView     UIView *view = [[[UIView alloc] init] autorelease];     // 2. 設定fram(100, 100, 200, 40)     view.frame = CGRectMake(100, 100, 200, 40);     // 3. 設定背景顏色     view.backgroundColor = [UIColor yellowColor];     //    view.backgroundColor = [UIColor colorWithHue:0.2 saturation:0.6 brightness:0.4 alpha:1];     // 代表三原色     // 4. 添加window     [self.window addSubview:view]; // view.retainCount 加一     //    [view release];
四、視圖操作
/*     * 根據下標插入視圖     * 最底層為0     * self.window insertSubview:<#(UIView *)#> atIndex:<#(NSInteger)#>     * 已經放到frame上面了     * self.window sendSubviewToBack:<#(UIView *)#>  最下面     * self.window bringSubviewToFront:<#(UIView *)#>  最上面     */    UIView *redView = [[UIView alloc] init];    redView.frame = CGRectMake(100, 100, 150, 150);    redView.backgroundColor = [UIColor redColor];    [self.window addSubview:redView];    [redView release];    // 刪除視圖    [whiteView removeFromSuperview];

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.