关于UIView的clipsTobounds属性的了解

关于clipsTobounds的属性,简单了解。

1.首先UIView的clipsTobounds的SDK中的描述

 @property(nonatomic)   BOOL   clipsToBounds;  // When YES, content and subviews are clipped to the bounds of the view. Default is NO.

2.Clip的意思是剪裁,bounds的意思是自身的边界,所以描述的意思:如果clipsToBounds的值是YES,那么子视图内容范围超出父视图的边界,超出的部分就会被剪裁掉

- (void)viewDidLoad {
[super viewDidLoad];
//黑色View
UIView *blackView = [UIView new];
greenView.frame = CGRectMake(0, 0, 250, 250);
greenView.backgroundColor = [UIColor blackColor];
greenView.center = self.view.center;
greenView.clipsToBounds = YES;
[self.view addSubview:greenView];
//红色View
UIView *redView = [UIView new];
redView.frame = CGRectMake(0, 0, 100, 400);
redView.backgroundColor = [UIColor redColor];
redView.center = self.view.center;
[greenView addSubview:redView];}

红色View添加到黑色View上,红色View超出黑色View的部分被剪裁掉

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容