2015-08-10 25 views
16

Sto usando questo codice per arrotondare i 2 angoli di un pulsante.Utilizzo di UIBezierPath: byRoundingCorners: con Swift 2 e Swift 3

let buttonPath = UIBezierPath(roundedRect: button.bounds, byRoundingCorners: UIRectCorner.TopLeft | UIRectCorner.BottomLeft, cornerRadii: CGSizeMake(1.0, 1.0)) 

getta un errore:

binary operator '|' cannot be applied to two UIRectCorner operands.

Come si utilizza questo metodo in Swift 2.0?

risposta

28

Swift 2:

let buttonPath = UIBezierPath(roundedRect: button.bounds, byRoundingCorners: [UIRectCorner.TopLeft , UIRectCorner.BottomLeft], cornerRadii: CGSizeMake(1.0, 1.0)) 

Swift 3:

let buttonPath = UIBezierPath(roundedRect: button.bounds, byRoundingCorners: [UIRectCorner.topLeft , UIRectCorner.bottomLeft], cornerRadii: CGSize(width:1.0, height:1.0)) 
11

In questo caso a Swift 2.0 è necessario per rendere l'unione di due angoli. F. es .:

let corners = UIRectCorner.TopLeft.union(UIRectCorner.BottomLeft) 
let buttonPath = UIBezierPath(roundedRect: button.bounds, byRoundingCorners: corners, cornerRadii: CGSizeMake(1.0, 1.0)) 

Funziona con Swift 2 e Swift 3