简体   繁体   English

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

[英]Using UIBezierPath:byRoundingCorners: with Swift 2 and Swift 3

I'm using this code to make 2 corners of a button rounded. 我正在使用此代码使按钮的2个角变圆。

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. 不能应用于两个UIRectCorner操作数。

How do I use this method in Swift 2.0? 如何在Swift 2.0中使用此方法?

Swift 2: 斯威夫特2:

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

Swift 3 and Swift 4: Swift 3Swift 4:

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

In this case in swift 2.0 is required to make union of two corners. 在这种情况下,需要在swift 2.0中将两个角合并。 F. ex.: F.例如:

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 适用于Swift 2Swift 3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM