小编dsk*_*306的帖子

UITableViewCell 的四舍五入

我想让我的 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)

uitableview ios swift

3
推荐指数
1
解决办法
3236
查看次数

标签 统计

ios ×1

swift ×1

uitableview ×1