如何为UIBezierPath提供cornerRadius

rol*_*JKS 7 cornerradius cashapelayer ios uibezierpath swift

我使用以下代码创建了一个矩形,现在我需要舍入这个矩形的角.但是我找不到一个名为layer.cornerRadius的属性,有人可以帮帮我吗?

    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
    }
}
Run Code Online (Sandbox Code Playgroud)

Bho*_*ani 10

您可以使用以下方法制作所有角落视图...

 UIBezierPath(roundedRect: anyView.bounds, cornerRadius: CGSize(width: 10.0, height: 10.0))
Run Code Online (Sandbox Code Playgroud)

如果你想要特定的角落在下面的方法使用.

 UIBezierPath(roundedRect: anyView.bounds,
        byRoundingCorners: .BottomLeft | .BottomRight,
        cornerRadius: CGSize(width: 10.0, height: 10.0))
Run Code Online (Sandbox Code Playgroud)

  • 你可以为星形等自定义形状建议圆角. (2认同)

Vvk*_*Vvk 6

使用这样:

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
Run Code Online (Sandbox Code Playgroud)

for All Corner Radius编辑此内容

[.TopRight,.TopLeft,.BottomRight, .BottomLeft]
Run Code Online (Sandbox Code Playgroud)