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