UI第一讲(UIView)

1.//
//   AppDelegate.h
//   LessonUIView01_6.23
//
//   Created by lanouhn on 15/6/23.
//   Copyright (c) 2015年 Wangcong. All rights reserved.
//

#import

@interface AppDelegate : UIResponder

@property (retain, nonatomic) UIWindow *window;


@end

2.//
//   AppDelegate.m
//   LessonUIView01_6.23
//
//   Created by lanouhn on 15/6/23.
//   Copyright (c) 2015年 Wangcong. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()
//延展里的方法声明   私有方法
- (void)sayHello;//可以不写....延展
@end

@implementation AppDelegate
- (void)dealloc{
       [_window release];
       [super dealloc];
}
//程序的入口, 当应用程序加载内容时触发, 也就是我们想要呈现给用户的内容, 都要写在此方法里
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOp tions:(NSDictionary *)launchOptions {
       //创建应用程序窗口对象, UIWindow窗口, 负责将内容呈现给用户
       self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

       // Override point for customization after application launch.
       //为窗口对象给一个颜色
       self.window.backgroundColor = [UIColor whiteColor];
       //让窗口成为应用程序的主窗口, 用来显示UI
       [self.window makeKeyAndVisible];
      
      
      
       //UIView视图     所有能看到的内容都属于UIView或者是UIView的子类
       //对于不同尺寸的屏幕像素点
     
     
       //blueView
//       UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
//       blueView.backgroundColor = [UIColor blueColor];
//       [self.window addSubview:blueView];
//       [blueView release];
//       //redView
//       UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 100, 100)];
//       redView.backgroundColor = [UIColor redColor];
//               //打印一下bounds   fram 是针对于父视图的原点坐标位置而言的, bounds是针对与自身原点坐标而言, 默认为 (0, 0)
//       //能改变一个视图位置的因素就是父视图的原点坐标位置
//       NSLog(@"bounds = %@", NSStringFromCGRect(blueView.bounds));
//       //改变blueView的bounds
//       blueView.bounds = CGRectMake(-50, -50, 200, 200);
//      
//      
//       [blueView addSubview:redView];
//       [redView release];
       //UIView的几个重要属性
     
       //redView
       UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(50, 50 , 200, 200)];
       redView.backgroundColor = [UIColor redColor];
       [self.window addSubview:redView];
       [redView release];
       //blueView
       UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(70, 70, 200, 200)];
       blueView.tag = 102;
       blueView.backgroundColor = [UIColor blueColor];
       [self.window addSubview:blueView];
       [blueView release];
       //yellowView
       UIView *yellowView = [[UIView alloc] initWithFrame:CGRectMake(90, 90, 200, 200)];
       //tag: 作为视图的唯一标示, 一般tag值给一个100以上   而且设置的tag值不能重复
       yellowView.tag = 101;
       yellowView.backgroundColor = [UIColor yellowColor];
       [self.window addSubview:yellowView];
       [yellowView release];
       //添加一个视图
       //grayView
       UIView *grayView = [[UIView alloc] initWithFrame:CGRectMake(100, 10, 30, 400)];
       grayView.backgroundColor = [UIColor grayColor];
       //1.添加到window上面     越后添加的视图显示就在上层
       [self.window addSubview:grayView];
       //2.插入到某个视图的下面
       //[self.window insertSubview:grayView belowSubview:yellowView];
       //3.插入到某个视图的上面
       //[self.window insertSubview:grayView aboveSubview:redView];
       //4.随意插入到任何位置
       //[self.window insertSubview:grayView atIndex:2];
       //二, 调整视图之间的层级关系   将此视图放到视图层级的人最后面,最下面
       //[self.window sendSubviewToBack:blueView];
       //将视图层级调到最上层
       //[self.window bringSubviewToFront:redView];
     //交换两个视图的位置     交换的是视图层级关系 注意: 交换的是视图在父视图当中的层级关系而已
       //[self.window exchangeSubviewAtIndex:0 withSubviewAtIndex:2];
       //移除视图   把该视图从父视图当中移除
       //[grayView removeFromSuperview];
       //[redView removeFromSuperview];
       //使用当前类的对象self调用方法
       [self sayHello];
       [grayView release];
      
      
      
       return YES;
}
- (void)sayHello{
       //通过tag值访问视图对象   父视图调用viewWithTag: 方法
       //此时的newView就是tag值为101的yellowView
  UIView *newView = [self.window viewWithTag:101];
       newView.backgroundColor = [UIColor blackColor];
}
- (void)applicationWillResignAct ive:(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)applicationDidEnterBackg round:(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)applicationWillEnterFore ground:(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)applicationDidBecomeActi ve:(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 applicationDidEnterBackg round:.
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值