等同于 swift 中的 UIButtonTypeRoundedRect?
Equivalent to UIButtonTypeRoundedRect in swift?
当我尝试在 swift 中使用 UIButtonType
时,UIButtonTypeRoundedRect 不再存在:
在 Swift 中是否有等效项,或者我是否需要创建一个新的子类才能获得相同的外观?
您需要改用 UIButtonTypeSystem
。
只需使用一个普通按钮并偷工减料:
let button = UIButton()
button.layer.cornerRadius = 3.0
button.clipsToBounds = true
它不在 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.
当我尝试在 swift 中使用 UIButtonType
时,UIButtonTypeRoundedRect 不再存在:
在 Swift 中是否有等效项,或者我是否需要创建一个新的子类才能获得相同的外观?
您需要改用 UIButtonTypeSystem
。
只需使用一个普通按钮并偷工减料:
let button = UIButton()
button.layer.cornerRadius = 3.0
button.clipsToBounds = true
它不在 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.