• ios 让tableview 的section cell整体圆角


    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

        

        // Cell 分区圆角

        CGFloat radius = 8;

        if ([tableView numberOfRowsInSection:indexPath.section] == 1) {

            // 当前section有且仅有1行,则四个角都要绘制圆角

            UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.bounds cornerRadius:radius];

            CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];

            maskLayer.frame = cell.bounds;

            maskLayer.path = maskPath.CGPath;

            cell.layer.mask = maskLayer;

        } else {

            // 当前section不止1行

            if (indexPath.row == 0) {

                // 当前cell为第一行

                UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.bounds

                                                           byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight

                                                                 cornerRadii:CGSizeMake(radius, radius)];

                CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];

                maskLayer.frame = cell.bounds;

                maskLayer.path = maskPath.CGPath;

                cell.layer.mask = maskLayer;

              

            } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section] - 1) {

                // 当前cell为最后一行

                UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.bounds

                                                           byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight

                                                                 cornerRadii:CGSizeMake(radius, radius)];

                CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];

                maskLayer.frame = cell.bounds;

                maskLayer.path = maskPath.CGPath;

                cell.layer.mask = maskLayer;

            } else {

                // 当前cell为中间行

                cell.layer.mask = nil;

            }

        }

    }

  • 相关阅读:
    html网页设计大学生作业成品——公益校园网站设计与实现(HTML+CSS+JavaScript)
    Elasticsearch RestHighLevelClient API 使用总结
    JUnit 5 单元测试教程
    蓝桥等考Python组别九级004
    时间序列预测:用电量预测 02 KNN(K邻近算法)
    git常用命令
    Visual Studio 安装离线插件 vsix 及常用插件
    (2022版)一套教程搞定k8s安装到实战 | Deployment
    ModbusTCP、TCP/IP都走网线,一样吗?
    前端最新2022面试题(JS)
  • 原文地址:https://blog.csdn.net/Dawe1/article/details/133248406