关于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的部分被剪裁掉

你可能感兴趣的:(关于UIView的clipsTobounds属性的了解)