【问题标题】:Using UIBezierPath:byRoundingCorners: with Swift 2 and Swift 3使用 UIBezierPath:byRoundingCorners: 与 Swift 2 和 Swift 3
【发布时间】:2015-11-02 09:15:30
【问题描述】:

我正在使用此代码使按钮的 2 个角变圆。

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

它会抛出一个错误:

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

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

【问题讨论】:

    标签: ios swift uibezierpath rounded-corners


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      在这种情况下,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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-11-13
        • 2017-03-04
        • 1970-01-01
        • 2017-02-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多