iOS UI01_UIView

//

//  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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值