Swift UIView绘制对角线一侧和圆角

Swift UIView draw diagonal one side and round corner

我正在画一些斜边的视图

像这样:

代码:

    let layerWidth = layer.frame.width
    let bezierPath = UIBezierPath()
    let pointA = CGPoint(x: 0, y: 44)
    let pointB = CGPoint(x: 150, y: 0)
    let pointC = CGPoint(x: layerWidth, y: 0)
    let pointD = CGPoint(x: layerWidth, y:44)
    bezierPath.move(to: CGPoint(x: pointA.x, y: pointA.y) )
    bezierPath.addLine(to: CGPoint(x: pointB.x, y: pointB.y))
    bezierPath.addLine(to: pointC)
    bezierPath.addLine(to: pointD)
    bezierPath.close()
    let shapeLayer = CAShapeLayer()
    shapeLayer.path = bezierPath.cgPath
    layer.addSublayer(shapeLayer)

如你所见,一切都很好,但我想把角弄圆

像这样:

我怎样才能达到这个结果?

添加: 收到结果后,我想将此表单设置为另一个视图的遮罩,但有一个问题:第二个视图有边框,如果我设置自己的表单,我会丢失部分边框

代码:

layer.mask = shapeLayer

错误结果:

Okey im founded way -

只要写4点就好:

        let grayPath = UIBezierPath()
        addArcs(
            to: grayPath,
            pointsAndRadii: [
                (point: CGPoint(x: 0, y: 0), radius: 2),
                (point: CGPoint(x: self.bounds.width - 104, y: 0), radius: 10),
                (point: CGPoint(x: self.bounds.width, y: self.bounds.height), radius: 2),
                (point: CGPoint(x: 104, y: self.bounds.height), radius: 6),
            ])
        grayPath.close()

下一组掩码:

let shapeLayer = CAShapeLayer()
shapeLayer.path = grayPath.cgPath
layer.mask = shapeLayer

如果你有更高效的方式或者更好的性能,写出来)