How to give cornerRadius for UIBezierPath

I created a rectangle using the following code, and now I need to round the corners of this rectangle. but I cannot find a property called layer.cornerRadius, can anyone help me?

    class OvalLayer: CAShapeLayer {

    let animationDuration: CFTimeInterval = 0.3

    override init() {
        super.init()
        fillColor = Colors.green.CGColor
        path = ovalPathSmall.CGPath
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
var ovalPathStart: UIBezierPath {
        let path = UIBezierPath(ovalInRect: CGRect(x: 0.0, y: 0.0, width: 100.0, height: 100.0))

        return path
    }
}
+4
source share
4 answers

You can use the method below to make the entire viewing angle ...

 UIBezierPath(roundedRect: anyView.bounds, cornerRadius: CGSize(width: 10.0, height: 10.0))

If you need a specific angle, to make a round use below the method.

 UIBezierPath(roundedRect: anyView.bounds,
        byRoundingCorners: .BottomLeft | .BottomRight,
        cornerRadius: CGSize(width: 10.0, height: 10.0))
+6
source

use the following:

let pathWithRadius = UIBezierPath(roundedRect:yourView.bounds, byRoundingCorners:[.TopRight, .TopLeft], cornerRadii: CGSizeMake(5.0, 5.0))
let maskLayer = CAShapeLayer()
maskLayer.pathWithRadius = pathWithRadius.CGPath
yourView.layer.mask = maskLayer

for all angular radii edit this

[.TopRight,.TopLeft,.BottomRight, .BottomLeft]
+6
source

let path1 = UIBezierPath(roundedRect: CGRect, cornerRadius: CGFloat)

let path1 = UIBezierPath(roundedRect:  CGRect, byRoundingCorners: UIRectCorner, cornerRadii: CGSize))
+2

c:

UIBezierPath* path = [UIBezierPath
    bezierPathWithRoundedRect: CGRectMake(0, 0, 150, 153)
                 cornerRadius: 50];

SWIFT:

var path: UIBezierPath = UIBezierPath(roundedRect: CGRectMake(0, 0, 150, 153), cornerRadius: 50)

Hope this helps.

+1
source

Source: https://habr.com/ru/post/1626297/


All Articles