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

效果:

Simulator Screen Shot - iPhone 13 - 2022-02-10 at 19.44.11.png
解决方案:
            cell.contentView.layer.rasterizationScale = UIScreen.main.scale
            cell.contentView.layer.shouldRasterize = true
            cell.contentView.layer.maskedCorners = [.layerMaxXMinYCorner]
            cell.contentView.layer.cornerRadius = 10

修改后效果:

Simulator Screen Shot - iPhone 13 - 2022-02-10 at 19.44.30.png
上一篇下一篇

猜你喜欢

热点阅读