你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS UI01_UIView

iOS UI01_UIView

編輯:IOS開發綜合

//

// AppDelegate.m

// UI01_UIView

//

// Created by dllo on 15/7/29.

// Copyright (c) 2015年 zhozhicheng. All rights reserved.

//

 

#import AppDelegate.h

 

@interface AppDelegate ()

 

@property(nonatomic,retain)UIView *myView;

 

// 宏

#define WIDTH self.window.frame.size.width

#define HEIGHT self.window.frame.size.height

 

 

@end

 

@implementation AppDelegate

-(void)dealloc

{

[_myView release];

[_window release];

[superdealloc];

}

 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

//創建一個和屏幕一般大的window

self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];

// Override point for customization after application launch.

//給window一個背景顏色

self.window.backgroundColor = [UIColoryellowColor];

//讓當前的window在應用程序中可見並顯示出來

[self.windowmakeKeyAndVisible];

//對window進行釋放

[_window release];

 

//UIView

// 1.創建一個UIView的對象

UIView *view1=[[UIViewalloc] initWithFrame:CGRectMake(100, 100, 100, 100)];

// 2.給view1設置背景顏色

view1.backgroundColor=[UIColorblueColor];

// 3.把視圖貼到窗口上

[self.windowaddSubview:view1];

// 4.釋放

[view1release];

//視圖添加到父視圖的數組之後,數組會增加視圖的引用計數,相應的也就可以在添加之後對視圖進行釋放

 

 

UIView *view2=[[UIViewalloc] initWithFrame:CGRectMake(130, 130, 100, 100)];

view2.backgroundColor=[UIColorwhiteColor];

[self.windowaddSubview:view2];

[view2release];

 

UIView *view3=[[UIViewalloc] initWithFrame:CGRectMake(160, 160, 100, 100)];

view3.backgroundColor=[UIColorredColor];

[self.windowaddSubview:view3];

[view3release];

//視圖的坐標起始位置在自己的父視圖的左上角

NSLog(@%g,WIDTH);

NSLog(@%g,HEIGHT);

//一個視圖可以有多個子視圖,但是一個視圖只能有一個父視圖

// 父視圖

NSLog(@%@,view2.superview);

 

// 子視圖

NSLog(@%@,self.window.subviews);

//先創建,先添加到subview的視圖會在層級關系的最下面

//通過父視圖來管理他身上所有子視圖的層級關系

//父視圖把指定的子視圖放在最上面

[self.windowbringSubviewToFront:view2];

//父視圖把指定的子視圖放在最下面

[self.windowsendSubviewToBack:view2];

 

//用視圖的frame屬性,對視圖位置大小進行重新設置

view1.frame=CGRectMake(190, 190, 120, 120);

 

self.myView =[[UIViewalloc] initWithFrame:CGRectMake(200, 200, 100, 100)];

self.myView.backgroundColor=[UIColorgrayColor];

[self.windowaddSubview:self.myView];

[_myView release];

 

// 透明度

view3.alpha = 0.5;

// tag值

// tag設置不能為0,不能重復

view1.tag = 1000;

UIView *tempView = [self.windowviewWithTag:1000];

NSLog(@%p,tempView);

NSLog(@%p,view1);

 

return YES;

\}

- (void)applicationWillResignActive:(UIApplication *)application {

// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}

 

- (void)applicationDidEnterBackground:(UIApplication *)application {

// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}

 

- (void)applicationWillEnterForeground:(UIApplication *)application {

// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}

 

- (void)applicationDidBecomeActive:(UIApplication *)application {

// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}

 

- (void)applicationWillTerminate:(UIApplication *)application {

// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}

 

@end


 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved