Search code examples
iosswifttransformuibezierpath

How to cut one edge of UIView in swift?


I am trying to cut one edge of UIView using Bezier path but i am unable to do it, could anyone please enlighten me ?

enter image description here

Thank You


Solution

  • You can try to assign this to the view

    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