如何在 swift 中切割 UIView 的一条边?

How to cut one edge of UIView in swift?

我正在尝试使用贝塞尔曲线路径切割 UIView 的一条边,但我做不到,谁能告诉我吗?

谢谢

您可以尝试将其分配给视图

class RightView : UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

    override func draw(_ rect: CGRect) {

        guard let context = UIGraphicsGetCurrentContext() else { return }
        context.beginPath()
        context.move(to: CGPoint(x: rect.maxX, y: rect.minY))
        context.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY))
        context.addLine(to: CGPoint(x:rect.maxX - 50, y: rect.maxY))
        context.closePath()

        context.setFillColor(UIColor.white.cgColor)
        context.fillPath()
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        self.layer.borderColor = UIColor.black.cgColor
        self.layer.borderWidth = 1
    }
}