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

20

我正在使用这段代码使按钮的两个角变圆。

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

它抛出一个错误:

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

我如何在Swift 2.0中使用这个方法?

2个回答

42

Swift 2:

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

Swift 3Swift 4:

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

12

在Swift 2.0中,需要合并两个角落。例如:

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

适用于 Swift 2Swift 3


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接