UIView的clipsTobounds属性

本文探讨了在iOS开发中如何通过调整视图的clipsToBounds属性来优化视图层级和布局,确保视图按预期显示,避免部分视图被遮挡的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载自:http://hi.baidu.com/marktian/item/8c727012013ecca1feded5f8

项目中的代码如下:

- (void)initTableView

{

    if (!_headView){

        [self createHeadView];

    }

    

    if (!_tableView) {

        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];

    }

    _tableView.dataSource =self;

    _tableView.delegate = self;

    _tableView.backgroundColor = [UIColor clearColor];

    _tableView.backgroundView = nil;

    _tableView.clipsToBounds = YES;

    _tableView.showsHorizontalScrollIndicator = NO;

    _tableView.showsVerticalScrollIndicator = NO;

    _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;

    

    

    _tableView.tableHeaderView = _headView;

    _tableView.separatorColor = [UIColor colorWithRed:211.f/255.f green:215.f/255.f blue:221.0f/255.0f alpha:1.0f];

    [self.view addSubview:_tableView];

}


如题,有两个view: view1,view2
view2添加view1到中,如果view2大于view1,或者view2的坐标不全在view1的范围内,view2是盖着view1的,意思就是超出的部份也会画出来

UIView有一个属性,clipsTobounds 默认情况下是NO。
如果,我们想要view2把超出的那部份隐藏起来的话,就得改变它的父视图也就view1的clipsTobounds属性值。
view1.clipsTobounds = YES;

no的情况:



yes的情况:

 

ZZ FROM COCOACHINA



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值