【问题标题】:Equivalent to UIButtonTypeRoundedRect in swift?相当于swift中的UIButtonTypeRoundedRect?
【发布时间】:2015-07-20 16:18:04
【问题描述】:

当我尝试在 swift 中使用 UIButtonType 时,UIButtonTypeRoundedRect 不再存在:

在 Swift 中是否有等价物,还是我需要创建一个新的子类才能获得相同的外观?

【问题讨论】:

  • 我无法想象这是 实际上 Swift 特有的。我很确定按钮类型在 iOS7 中已被弃用。
  • 是的,先生 - 事实证明这不是 Swift 特定的,我只是在快速迁移应用程序时偶然发现它。 #hattip

标签: ios swift uibutton uikit


【解决方案1】:

它不在 Xcode 6.4 中包含的 SDK 中:

enum UIButtonType : Int {

    case Custom // no button type
    @availability(iOS, introduced=7.0)
    case System // standard system button

    case DetailDisclosure
    case InfoLight
    case InfoDark
    case ContactAdd
}

但在 Xcode 7 中包含的 SDK 中,它又回来了并被标记为已弃用。

enum UIButtonType : Int {

    case Custom // no button type
    @available(iOS 7.0, *)
    case System // standard system button

    case DetailDisclosure
    case InfoLight
    case InfoDark
    case ContactAdd

    static var RoundedRect: UIButtonType { get } // Deprecated, use UIButtonTypeSystem instead
}

您应该使用System。如果它不符合您的需求,请不要继承 UIButton,使用自定义工厂方法 like this one

【讨论】:

    【解决方案2】:

    只需使用一个简单的按钮并自己切入角落:

    let button = UIButton()
    button.layer.cornerRadius = 3.0
    button.clipsToBounds = true
    

    【讨论】:

      【解决方案3】:

      您需要改用UIButtonTypeSystem

      UIButton Class Reference

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-02-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-08
        • 2020-09-11
        • 1970-01-01
        相关资源
        最近更新 更多