ios - 如何为 UIBezierPath 提供 cornerRadius

标签 ios swift uibezierpath cashapelayer cornerradius

我使用以下代码创建了一个矩形,现在我需要圆化这个矩形的角。但是我找不到名为 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
    }
}

最佳答案

您可以使用下面的方法来制作所有角落的视野...

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

如果你想让特定的角变圆,请使用下面的方法。

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

关于ios - 如何为 UIBezierPath 提供 cornerRadius,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35053805/

相关文章:

swift - Alamofire 未正确发送请求

ios - Swift3 中的 NSIndexPath 初始化有何变化?

ios - UIBezierPath 段连接导致间隙

ios - 为什么我的 iAds 广告在 iPad 上损坏

ios - 与其他应用程序共享应用程序商店 URL

ios - 在 IOS 10 上使用设备 CAMERA 会导致应用程序终止

来自小键盘的 iOS 9/Swift 2 输入找不到键盘

ios - 我怎样才能得到字典关键元素的区别?

ios - 更改 UIButton 矩形而不使用drawRect

ios - 如何用UIBezierPath删除徒手画?