我想把最后一个 UITableViewCell
底角做成圆形,我可以做到,但结果是边界没有正确绘制,任何人都对此类问题有同样的经验,请帮我。谢谢
cell.roundCorners([.bottomLeft, .bottomRight], radius: 8)
cell.clipsToBounds = true
cell.layer.masksToBounds = true
cell.layoutSubviews()
最佳答案
使用 UIBezierPath 圆角到最后一个单元格
let totalRow : Int = tableView.numberOfRows(inSection: indexPath.section)
//first get total rows in that section by current indexPath.
if indexPath.row == totalRow - 1 {
//this is the last row in section.
let maskLayer = CAShapeLayer()
maskLayer.path = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: [.bottomLeft,.bottomRight], cornerRadii: CGSize(width: 10, height: 10)).cgPath
cell.layer.mask = maskLayer
}else{
let maskLayer = CAShapeLayer()
maskLayer.path = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: [], cornerRadii: CGSize(width: 0, height: 0)).cgPath
cell.layer.mask = maskLayer
}
关于ios - UITableViewCell 圆角问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50487389/