我要让我的tableView看起来像这样的:四舍五入的UITableViewCell
,我有问题的。只有当我点击牢房时,我的右角才圆了。当视图显示它看起来像这样:
和这样的自来水后:
这里是我的代码:
extension UITableViewCell {
func round(corners: UIRectCorner, withRadius radius: CGFloat) {
let mask = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let shape = CAShapeLayer()
shape.frame = self.bounds
shape.path = mask.cgPath
self.layer.mask = shape
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
...
if numberOfRows(in: indexPath.section) == 1 {
cell.round(corners: [.bottomLeft, .bottomRight, .topLeft, .topRight], withRadius: 8)
} else {
if indexPath.row == 0 {
cell.round(corners: [.topLeft, .topRight], withRadius: 8)
}
if indexPath.row == numberOfRows(in: indexPath.section) - 1 {
cell.round(corners: [.bottomLeft, .bottomRight], withRadius: 8)
}
}
return cell
}
尝试将这些代码移动到'willDisplayCell' – Tj3n