Ios 取整表可视单元格
我想让我的tableView看起来像这样: 我对此有意见。我的右角只有在我敲了一下手机后才转过来。当视图出现时,它如下所示: 轻敲之后,像这样: 这是我的密码:Ios 取整表可视单元格,ios,swift,uitableview,Ios,Swift,Uitableview,我想让我的tableView看起来像这样: 我对此有意见。我的右角只有在我敲了一下手机后才转过来。当视图出现时,它如下所示: 轻敲之后,像这样: 这是我的密码: extension UITableViewCell { func round(corners: UIRectCorner, withRadius radius: CGFloat) { let mask = UIBezierPath(roundedRect: self.bounds, byRounding
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
}
必须为设计创建自定义UITableviewcell。对于tableviewcell Parentview,取cornerradius=2 这是因为当您第一次环绕单元格时,它不会在任何superview上绘制,因此它的帧是未知的。试着绕道而行
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
}
另外,我强烈建议您不要对单元格本身进行圆角处理,而是将背景视图添加到单元格中,使单元格的背景颜色清晰(单元格的内容视图也是如此),并使该视图具有圆角。祝你好运 根据您的屏幕截图, 我认为,你的限制没有设置好 或
您可以将自定义xib用作单元格。我已经有了自定义单元格,但它非常简单(只有2个IBO)。我不确定我是否理解你答案的第二部分。parentview.cornerradius=2(自定义单元格)尝试将这些代码移动到
willDisplayCell
非常感谢,我将尝试背景视图,也许它会解决其他一些问题。