2015-07-20 31 views
2

当我试图在迅速使用UIButtonType,UIButtonTypeRoundedRect不再存在:相当于swift中的UIButtonTypeRoundedRect?

enter image description here

是否有斯威夫特等同,或者我需要做一个新的子类来获得相同的外观?

+2

我无法想象这实际上是* Swift特有的。我很确定按钮类型在iOS7中已弃用。 – nhgrif

+0

正确的你是先生 - 事实证明这不是Swift特有的,我只是在一个应用程序的快速迁移期间发生的。 #hattip –

回答

3

这不是在SDK包含在Xcode 6.4:

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,它回来并标记为depreca特德。

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