如何快速切入UIView的边缘?

时间:2019-03-05 11:41:40

标签: ios swift transform uibezierpath

我正在尝试使用Bezier路径切开UIView的某个边缘,但我无法做到这一点,请问有人能启发我吗?

enter image description here

谢谢

1 个答案:

答案 0 :(得分:2)

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

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
    }
}

enter image description here