在项目中使用UIBezierPath给tableView 中cell添加圆角,出现了一条白线。
let bezierPath = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: cell.contentView.frame.size.height), byRoundingCorners: .topRight, cornerRadii: CGSize(width: 10, height: 10))
let shapeLayer = CAShapeLayer()
shapeLayer.frame = cell.contentView.bounds
shapeLayer.path = bezierPath.cgPath
cell.contentView.layer.mask = shapeLayer
效果:
解决方案1:添加描边颜色
let bezierPath = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: cell.contentView.frame.size.height), byRoundingCorners: .topRight, cornerRadii: CGSize(width: 10, height: 10))
let shapeLayer = CAShapeLayer()
shapeLayer.frame = cell.contentView.bounds
shapeLayer.path = bezierPath.cgPath
shapeLayer.strokeColor = self.backgroundColor?.cgColor
cell.contentView.layer.mask = shapeLayer
解决方案2:替换圆角添加方式
cell.contentView.layer.rasterizationScale = UIScreen.main.scale
cell.contentView.layer.shouldRasterize = true
cell.contentView.layer.maskedCorners = [.layerMaxXMinYCorner]
cell.contentView.layer.cornerRadius = 10
修改后效果: