iOS View的ClipsToBounds属性
今天在开发终于到了子视图超出父视图的部分不显示。然后就出现了这个<pre>ClipsToBounds</pre>属性了。
简单的说就是,当<pre>ClipsToBounds</pre>属性设置成YES的时,剪裁超出父视图范围的子视图部分。当设置成NO的时候,不剪裁超出父视图范围的子视图。
默认是NO 在scrollView中默认是YES
举个例子:
下面是红色view是蓝色view的子视图 ,父视图(蓝色view)的<pre>ClipsToBounds</pre>设置成NO;
<pre>
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(30,200, 200, 40)];
[self.view addSubview:textField];
textField.backgroundColor = [UIColor blueColor];
textField.clipsToBounds = NO;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, 3000, 4)];
[textField addSubview:label];
label.backgroundColor = [UIColor redColor];
</pre>
效果图如下:
clipsToBounds = NOClipsToBounds设置成YES;
<pre>
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(30,200, 200, 40)];
[self.view addSubview:textField];
textField.backgroundColor = [UIColor blueColor];
textField.clipsToBounds = YES;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, 3000, 4)];
[textField addSubview:label];
label.backgroundColor = [UIColor redColor];
</pre>
效果图如下:
clipsToBounds = YES