我要讓我的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