使用 UIBezierPath:byRoundingCorners:使用 Swift 2 和 Swift 3
Using UIBezierPath:byRoundingCorners: with Swift 2 and Swift 3
我正在使用此代码使按钮的两个角变圆。
let buttonPath = UIBezierPath(roundedRect: button.bounds,
byRoundingCorners: .TopLeft | .BottomLeft,
cornerRadii: CGSizeMake(1.0, 1.0))
它抛出一个错误:
binary operator '|' cannot be applied to two UIRectCorner operands.
如何在 Swift 2.0 中使用此方法?
Swift 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
我正在使用此代码使按钮的两个角变圆。
let buttonPath = UIBezierPath(roundedRect: button.bounds,
byRoundingCorners: .TopLeft | .BottomLeft,
cornerRadii: CGSizeMake(1.0, 1.0))
它抛出一个错误:
binary operator '|' cannot be applied to two UIRectCorner operands.
如何在 Swift 2.0 中使用此方法?
Swift 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