func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let radius = 8.0 //圆角
cell.backgroundColor = .clear
let normalLayer = CAShapeLayer()
let selectLayer = CAShapeLayer()
let bounds = cell.bounds.insetBy(dx:10.0, dy:0) //cell 左右缩进距离
let rowNum = tableView.numberOfRows(inSection: indexPath.section)
var bezierPath:UIBezierPath
if(rowNum==1) {
bezierPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: .allCorners, cornerRadii:CGSize(width: radius, height: radius))
}else{
if(indexPath.row==0) {
UITableView cell加圆角
该博客介绍了如何在Swift中为UITableView的Cell添加圆角效果。通过在`tableView:willDisplay cell:forRowAt:`代理方法中使用CAShapeLayer和UIBezierPath,根据单元格的位置动态设置圆角,并分别设置了正常状态和选中状态的背景颜色。

最低0.47元/天 解锁文章
698

被折叠的 条评论
为什么被折叠?



