我正在使用此代码使按钮的两个角变圆。
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. ex。:
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