0:首先还是通过纯的代码来实现
0:删除3个文件ViewController.h,ViewController.m,Main.storyboard
1:修改点击左边的蓝色按钮,然后选择general-》developer info-》main interface ,将这个main interface 晴空
2:然后再创建一个MainUIViewController ,它继承自UIViewController
1:AppDelegate.m的didfinshlaunchingwithoptions方法的更新
2:
//
// MainUIViewController.m
// FifthDemoFrameAndBounds
//
// Created by 千雅爸爸 on 16/10/9.
// Copyright © 2016年 kodulf. All rights reserved.
//
#import "MainUIViewController.h"
@interface MainUIViewController ()
@end
@implementation MainUIViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.view setBackgroundColor:[UIColor greenColor]];
//frame使用来给我们的视图控件去设置视图的气势的坐标和宽高的
UIView *childView =[[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
[childView setBackgroundColor:[UIColor yellowColor]];
[self.view addSubview:childView];
//bounds 的起始坐标永远都是0,0,这个最关键了
//用来记录边界尺寸的,可以理解为就是边界,
// default bounds is zero origin, frame size. animatable
UIView *childView1 =[[UIView alloc]initWithFrame:childView.frame];//相当于(100, 100, 100, 100)
[childView1 setBackgroundColor:[UIColor redColor]];
[childView addSubview:childView1];
UIView *childView2 =[[UIView alloc]initWithFrame:childView.bounds];//相当于(0,0,100,100)
[childView2 setBackgroundColor:[UIColor blackColor]];
[childView addSubview:childView2];
}
- (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