zoukankan      html  css  js  c++  java
  • UIView的clipsTobounds属性

    之前一直都没有搞懂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看看:


    红色视图最终突破了绿色视图的边界。

    该属性在实际project中还是很有用的,必需要了解清楚。



  • 相关阅读:
    TCP/IP详解V2(六)之TCP协议
    TCP/IP详解V2(四)之TCP协议
    TCP/IP详解V2(三)之TCP协议
    epoll源码剖析
    UDT源码剖析(二)之启动与结束
    TCP/IP详解V2(二)之UDP协议
    TCP/IP详解V2(一)之协议控制块
    UDT源码剖析(一)之总览
    SPI通信协议(SPI总线)学习
    第12章Cortex-M4-SPI-Bus
  • 原文地址:https://www.cnblogs.com/cxchanpin/p/7000614.html
Copyright © 2011-2022 走看看