clipsTobounds属性的作用
2015-08-20 15:13
351 查看
转:/article/2026159.html
之前一直都没有搞懂clipsTobounds属性的作用,前几天又遇到了这个属性,这次终于弄明白了。
首先看看UIView的clipsToubounds属性在SDK中的描述:
@property (nonatomic) BOOL clipsToBounds; // When YES, content and subviews are clipped to the bounds of the view. Default is NO.
这里的clip是修剪的意思,bounds是边界的意思是,合起来就是:如果子视图的范围超出了父视图的边界,那么超出的部分就会被裁剪掉。
写个Demo看看效果,代码如下:
- (void)viewDidLoad {
[super viewDidLoad];
UIView *greenView = [UIView new];
greenView.frame = CGRectMake(0, 0, 300, 300);
greenView.backgroundColor = [UIColor greenColor];
greenView.center = self.view.center;
greenView.clipsToBounds = YES;
[self.view addSubview:greenView];
UIView *redView = [UIView new];
redView.frame = CGRectMake(0, 0, 100, 400);
redView.backgroundColor = [UIColor redColor];
redView.center = self.view.center;
[greenView addSubview:redView];
}
运行结果如下:
![](http://img.blog.csdn.net/20140724224712046)
将greenView的clipsTobounds属性设为NO,其它不做任何改动(注意redView还是greenView的子视图)
greenView.clipsToBounds = NO;
再Run看看:
![](http://img.blog.csdn.net/20140724224823890)
红色视图终于突破了绿色视图的边界。
该属性在实际工程中还是非常实用的,必须要了解清楚。
之前一直都没有搞懂clipsTobounds属性的作用,前几天又遇到了这个属性,这次终于弄明白了。
首先看看UIView的clipsToubounds属性在SDK中的描述:
@property (nonatomic) BOOL clipsToBounds; // When YES, content and subviews are clipped to the bounds of the view. Default is NO.
这里的clip是修剪的意思,bounds是边界的意思是,合起来就是:如果子视图的范围超出了父视图的边界,那么超出的部分就会被裁剪掉。
写个Demo看看效果,代码如下:
- (void)viewDidLoad {
[super viewDidLoad];
UIView *greenView = [UIView new];
greenView.frame = CGRectMake(0, 0, 300, 300);
greenView.backgroundColor = [UIColor greenColor];
greenView.center = self.view.center;
greenView.clipsToBounds = YES;
[self.view addSubview:greenView];
UIView *redView = [UIView new];
redView.frame = CGRectMake(0, 0, 100, 400);
redView.backgroundColor = [UIColor redColor];
redView.center = self.view.center;
[greenView addSubview:redView];
}
运行结果如下:
将greenView的clipsTobounds属性设为NO,其它不做任何改动(注意redView还是greenView的子视图)
greenView.clipsToBounds = NO;
再Run看看:
红色视图终于突破了绿色视图的边界。
该属性在实际工程中还是非常实用的,必须要了解清楚。
相关文章推荐
- DOM事件简介
- js实现按钮颜色渐变动画效果
- 随笔(2015-18-19)
- 使用eclipse开发web项目中常见的中文乱码问题总结
- 一维线段树模板 (HDU 1166)解题报告
- Sdoi2015约数个数和题解莫比乌斯反演
- 《C算法》笔记7:词法解析树
- CGAffineTransform-缩放、移动、旋转
- CSting分配空间
- 也谈kendoUI的grid.
- xtrabackup备份mysql数据库
- 使用hiredis提供的接口访问redis中的ZSeT对象
- Android中的AlarmManager
- SSDB:高性能数据库服务器
- HDU4135
- An error has occurred. See error log for more details. java.lang.NullPointerException
- python中if __name__ == '__main__': 的解析
- 《梁祝》-化蝶(五线谱)
- 【转】tomcat下jndi的三种配置方式
- 一个提示窗口的对话框