- (void)creatViews {
//frame 坐标都是 相对于父视图坐标系的坐标
UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(30, 50, 200, 100)];
//设置背景颜色
redView.backgroundColor = [UIColor redColor];
UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)];
blueView.backgroundColor = [UIColor blueColor];
//frame 都是相对于父视图的
//获取视图的边框 前两项默认是 0 0
CGRect bounds = redView.bounds;
//把一个结构体转化为字符串打印
NSLog(@"%@",NSStringFromCGRect(bounds));
//{{0, 0}, {200, 100}}
//redView.bounds = CGRectMake(0, 0, 200, 100);
//我们一般使用bounds 来获取/修改视图的大小 前两项一般都是0
/*
确定一个视图的大小和位置 可以用frame 或者 bounds+center
bounds 和 frame的区别
1.frame 是相对于 父视图坐标系的坐标
bounds 是相对于自己坐标系的坐标
2.bounds 一般 就是前两项 0 0,一旦修改那么当前视图的自己的坐标系的位置就会改变,这样会影响当前视图子视图的位置
*/
//确定父子视图
[redView addSubview:blueView];
[blueView release];
[self.window addSubview:redView];
[redView release];
}
//frame 坐标都是 相对于父视图坐标系的坐标
UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(30, 50, 200, 100)];
//设置背景颜色
redView.backgroundColor = [UIColor redColor];
UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)];
blueView.backgroundColor = [UIColor blueColor];
//frame 都是相对于父视图的
//获取视图的边框 前两项默认是 0 0
CGRect bounds = redView.bounds;
//把一个结构体转化为字符串打印
NSLog(@"%@",NSStringFromCGRect(bounds));
//{{0, 0}, {200, 100}}
//redView.bounds = CGRectMake(0, 0, 200, 100);
//我们一般使用bounds 来获取/修改视图的大小 前两项一般都是0
/*
确定一个视图的大小和位置 可以用frame 或者 bounds+center
bounds 和 frame的区别
1.frame 是相对于 父视图坐标系的坐标
bounds 是相对于自己坐标系的坐标
2.bounds 一般 就是前两项 0 0,一旦修改那么当前视图的自己的坐标系的位置就会改变,这样会影响当前视图子视图的位置
*/
//确定父子视图
[redView addSubview:blueView];
[blueView release];
[self.window addSubview:redView];
[redView release];
}