UIView(17-08-03)

//
//  AppDelegate.m
//  UI01_UIView
//
//  Created by lanou3g on 17/8/3.
//  Copyright © 2017年 lanou3g. All rights reserved.
//

#import "AppDelegate.h"
#import "RootViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

//程序加载完成之后
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    //单例:整个生命周期内只有一个对象
    [UIScreen mainScreen];
    self.window.backgroundColor = [UIColor whiteColor];
    //让window作为主window并可见
    [self.window makeKeyAndVisible];
    //创建根视图对象
    RootViewController *rootViewController = [[RootViewController alloc] init];
    //将window的根视图设置为rootViewController
    self.window.rootViewController = rootViewController;
    
    NSLog(@"程序加载完成之后");
    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.
    
    NSLog(@"失去活跃状态");
}
//程序进入后台
- (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.
    NSLog(@"程序进入后台");
}
//将要进入前台
- (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.
    
    NSLog(@"将要进入前台");
}
//成为活跃状态
- (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.
    
    NSLog(@"成为活跃状态");
}
//程序将要结束时
- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    
    NSLog(@"程序将要结束时");
}

@end

//
//  RootViewController.m
//  UI01_UIView
//
//  Created by lanou3g on 17/8/3.
//  Copyright © 2017年 lanou3g. All rights reserved.
//

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController
//视图加载完成(自带的view)
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIView *redview = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
    redview.backgroundColor = [UIColor redColor];
    //将redview添加到self.view上
    [self.view addSubview:redview];
    
    UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 100, 100)];
    greenView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:greenView];
    //中心点
    greenView.center = CGPointMake(100, 100);
    NSLog(@"%@",NSStringFromCGRect(greenView.frame));
    
    //hidden 控制视图隐藏
    greenView.hidden = NO;
    //alpha 视图的透明度 (0是完全透明)
    greenView.alpha = 0.5f;
    //superview获取本视图的父视图
    NSLog(@"superView:%@",greenView.superview);
    //superview获取本视图的所有子视图
    NSLog(@"subViews:%@",self.view.subviews);
    //tag:给视图一个标记,用来找到该视图(系统保留1000以内,为了避免冲突,所以我们tag赋值通常在1000以上)
    greenView.tag = 1001;
    UIView *tagView = [self.view viewWithTag:1001];
    NSLog(@"%@",tagView);
    
    UIView *orangeView = [[UIView alloc] initWithFrame:CGRectMake(25, 25, 100, 100)];
    orangeView.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:orangeView];
    //在指定的index处插入子视图
//    [self.view insertSubview:orangeView atIndex:1];
    //在指定的视图上面添加子视图
    [self.view insertSubview:orangeView aboveSubview:redview];
    //从父视图中移除
    [orangeView removeFromSuperview];
    
    //bunds会影响子视图的位置 frame会影响父视图的位置
    
}
//收到内存警告
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 200,045评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,114评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 147,120评论 0 332
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,902评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,828评论 5 360
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,132评论 1 277
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,590评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,258评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,408评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,335评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,385评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,068评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,660评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,747评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,967评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,406评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,970评论 2 341

推荐阅读更多精彩内容

  • 小学语文修改病句的方法 修改病句是小学语文考试中常见的题型,在修改病句之前,我们应该清晰的了解有哪些病句现象,下面...
    王柯阅读 9,804评论 1 12
  • 谭宇军要来杭州,可一聚~
    鹰王守仁阅读 161评论 0 0
  • 今天开了周会,通报了一下这周的工作情况,总结下来感觉自己的沟通能力还是有待加强,想起自己的加班申请还没提交就去把审...
    Even丶阅读 169评论 0 0
  • 以前不懂事的时候 不加辨别的喝了无数碗鸡汤 所以这造成了现在各种情况下 我都可以从两个方面看问题 一面积极 一面消...
    M迷鹿M阅读 107评论 0 0
  • 时间真的是白驹过隙,晃眼之间就又过了一个月了。在以前,小时候,总是觉得时间好慢好慢,慢到想明天就长大。而现在,时间...
    曉彤阅读 323评论 0 0