frame:描述当前视图在其父视图中的位置和大小。
bounds:描述当前视图在其自身坐标系统中的位置和大小。
center:描述当前视图的中心点在其父视图中的位置。
- (void)viewDidLoad {
[super viewDidLoad];
UIView *view0 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 120, 120)];
view0.backgroundColor = [UIColor blueColor];
[self.view addSubview:view0];
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 120, 120)];
[view1 setBounds:CGRectMake(20, 0, 10, 120)];
view1.backgroundColor = [UIColor redColor];
[self.view addSubview:view1];//添加到self.view
NSLog(@"view1 frame:%@========view1 bounds:%@",NSStringFromCGRect(view1.frame),NSStringFromCGRect(view1.bounds));
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
view2.backgroundColor = [UIColor yellowColor];
[view1 addSubview:view2];//添加到view1上,[此时view1坐标系左上角起点为(-20,-20)]
NSLog(@"view2 frame:%@========view2 bounds:%@",NSStringFromCGRect(view2.frame),NSStringFromCGRect(view2.bounds));
// Do any additional setup after loading the view, typically from a nib.
}