簡體   English   中英

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

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

我正在使用此代碼使按鈕的2個角變圓。

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

它拋出一個錯誤:

二進制運算符'|' 不能應用於兩個UIRectCorner操作數。

如何在Swift 2.0中使用此方法?

斯威夫特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))

在這種情況下,需要在swift 2.0中將兩個角合並。 F.例如:

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

適用於Swift 2Swift 3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM