[英]Using UIBezierPath:byRoundingCorners: with Swift 2 and Swift 3
我正在使用此代码使按钮的2个角变圆。
let buttonPath = UIBezierPath(roundedRect: button.bounds,
byRoundingCorners: .TopLeft | .BottomLeft,
cornerRadii: CGSizeMake(1.0, 1.0))
它抛出一个错误:
二进制运算符'|' 不能应用于两个UIRectCorner操作数。
如何在Swift 2.0中使用此方法?
斯威夫特2:
let buttonPath = UIBezierPath(roundedRect: button.bounds,
byRoundingCorners: [.TopLeft , .BottomLeft],
cornerRadii: CGSizeMake(1.0, 1.0))
Swift 3和Swift 4:
let buttonPath = UIBezierPath(roundedRect: button.bounds,
byRoundingCorners: [.topLeft ,.bottomLeft],
cornerRadii: CGSize(width:1.0, height:1.0))
在这种情况下,需要在swift 2.0中将两个角合并。 F.例如:
let corners = UIRectCorner.TopLeft.union(UIRectCorner.BottomLeft)
let buttonPath = UIBezierPath(roundedRect: button.bounds,
byRoundingCorners: corners,
cornerRadii: CGSizeMake(1.0, 1.0))
适用于Swift 2和Swift 3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.