• 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;

            }

        }

    }

  • 相关阅读:
    最近面试被问到的vue题
    Shiro自定义Token
    重塑运维系统,跨越烟囱式建设的陷阱
    WSL安装异常:WslRegisterDistribution failed with error: 0xc03a001a
    2023NOIP A层联测19-多边形
    maven jar依赖地址
    微信小程序授权登录
    MySQL入门第三天——数据表的约束
    EIP-3664合约研究笔记06--text功能分析
    03-Flask-工程配置加载方式
  • 原文地址:https://blog.csdn.net/Dawe1/article/details/133248406