我想让我的 tableView 看起来像这样:
我有问题。仅当我点击单元格后,我的右角才会变圆。当视图出现时,它看起来像这样:
点击后像这样:
这是我的代码:
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) …Run Code Online (Sandbox Code Playgroud)