Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using UIBezierPath:byRoundingCorners: with Swift 2 and Swift 3

I'm using this code to make 2 corners of a button rounded.

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

It throws an error:

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

How do I use this method in Swift 2.0?

like image 881
sanjihan Avatar asked Aug 10 '15 12:08

sanjihan


2 Answers

Swift 2:

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

Swift 3 and Swift 4:

let buttonPath = UIBezierPath(roundedRect: button.bounds, 
                              byRoundingCorners: [.topLeft ,.bottomLeft], 
                              cornerRadii: CGSize(width:1.0, height:1.0))
like image 171
Juri Noga Avatar answered Nov 01 '22 21:11

Juri Noga


In this case in swift 2.0 is required to make union of two corners. F. ex.:

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

Works with Swift 2 and Swift 3

like image 11
lukszar Avatar answered Nov 01 '22 21:11

lukszar