Swift:使用UIBezierPath添加圆角后视图底部出现白
2022-02-10 本文已影响0人
蛋哥是只猫
在项目中使用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
效果:
解决方案:
cell.contentView.layer.rasterizationScale = UIScreen.main.scale
cell.contentView.layer.shouldRasterize = true
cell.contentView.layer.maskedCorners = [.layerMaxXMinYCorner]
cell.contentView.layer.cornerRadius = 10
修改后效果: