2015-07-20 97 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