美文网首页
Tableview设置圆角

Tableview设置圆角

作者: follow_er | 来源:发表于2023-08-15 14:59 被阅读0次

使用如下代码或tableview的style设置为inset Grouped

if indexPath.row == 0 {
                        var maskPath: UIBezierPath = UIBezierPath()
                        if array.count > 1 {
                            maskPath = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 8, height: 8))
                        } else {
                            maskPath = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: .allCorners, cornerRadii: CGSize(width: 8, height: 8))
                        }
                        let maskLayer = CAShapeLayer().then {
                            $0.frame = cell.bounds
                            $0.path = maskPath.cgPath
                        }
                        cell.layer.mask = maskLayer
                    } else if indexPath.row == (array.count - 1) {
                        let maskPath = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: [.bottomLeft, .bottomRight], cornerRadii: CGSize(width: 8, height: 8))
                        let maskLayer = CAShapeLayer().then {
                            $0.frame = cell.bounds
                            $0.path = maskPath.cgPath
                        }
                        cell.layer.mask = maskLayer
                    }

相关文章

网友评论

      本文标题:Tableview设置圆角

      本文链接:https://www.haomeiwen.com/subject/uvuhmdtx.html