Using UIBezierPath:byRoundingCorners: with Swift 2 and Swift 3

假如想象 提交于 2019-12-03 11:06:59

问题


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?


回答1:


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))



回答2:


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



来源:https://stackoverflow.com/questions/31919867/using-uibezierpathbyroundingcorners-with-swift-2-and-swift-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!