//
// ViewController.m
// UILable
//
// Created by mac on 2016/10/25.
// Copyright © 2016年 mac. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
// 创建三个视图对象
UIView* view01 =[[UIView alloc] init];
UIView* view02 =[[UIView alloc] init];
UIView* view03 =[[UIView alloc] init];
view01.frame = CGRectMake(100, 100, 150, 150);
view01.backgroundColor = [UIColor blueColor];
view02.frame = CGRectMake(125, 125, 150, 150);
view02.backgroundColor = [UIColor orangeColor];
view03.frame = CGRectMake(150, 150, 150, 150);
view03.backgroundColor = [UIColor greenColor];
// 将三个视图对象显示到屏幕上
// 并且添加到父亲视图上
// 哪一个视图被先添加到父亲视图中,就先绘制哪一个视图
// 哪一个视图被最后添加到父亲视图中,就最后绘制哪一个视图
[self.view addSubview:view01];
[self.view addSubview:view02];
[self.view addSubview:view03];
// 将某一个视图调整到最前面
// 参数:UIView对象,调整哪一个视图到最前方
[self.view bringSubviewToFront:view01];
// 将某一个视图调整到最后面
// 参数:UIView对象,调整哪一个视图到最后方
[self.view sendSubviewToBack:view03];
// subviews管理所有self.view的子视图的数组
// 按照顺序添加的,viewBack就是view01
[view01 removeFromSuperview ];
// 如果吧view01清除掉,viewBack变成了view02了
// 一个view可以有多个子视图(subview)但是智能有一个父视图(Superview)
UIView* viewFront = self.view.subviews[2];
UIView* viewBack = self.view.subviews[0];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end