使用如下代码或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
}
网友评论