使用UIBezierPath:byRoundingCorners:使用Swift 2和Swift 3

san*_*han 20 rounded-corners ios uibezierpath swift

我正在使用此代码使按钮的两个角变圆.

let buttonPath = UIBezierPath(roundedRect: button.bounds,
                              byRoundingCorners: .TopLeft | .BottomLeft, 
                              cornerRadii: CGSizeMake(1.0, 1.0))
Run Code Online (Sandbox Code Playgroud)

它抛出一个错误:

二元运算符'|' 不能应用于两个UIRectCorner操作数.

如何在Swift 2.0中使用此方法?

Jur*_*oga 38

斯威夫特2:

let buttonPath = UIBezierPath(roundedRect: button.bounds, 
                              byRoundingCorners: [.TopLeft , .BottomLeft], 
                              cornerRadii: CGSizeMake(1.0, 1.0))
Run Code Online (Sandbox Code Playgroud)

Swift 3Swift 4:

let buttonPath = UIBezierPath(roundedRect: button.bounds, 
                              byRoundingCorners: [.topLeft ,.bottomLeft], 
                              cornerRadii: CGSize(width:1.0, height:1.0))
Run Code Online (Sandbox Code Playgroud)


小智 11

在这种情况下,需要使用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))
Run Code Online (Sandbox Code Playgroud)

适用于Swift 2Swift 3