Ryan Kreager
Ryan Kreager

Reputation: 3581

Equivalent to UIButtonTypeRoundedRect in swift?

When I try to use UIButtonType in swift, UIButtonTypeRoundedRect no longer exists:

enter image description here

Is there an equivalent in Swift, or do I need to make a new subclass to get the same look?

Upvotes: 2

Views: 487

Answers (3)

zrzka
zrzka

Reputation: 21249

It's not in SDK included within 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
}

But in SDK included in Xcode 7, it's back and marked as deprecated.

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
}

You should use System. If it doesn't fit your needs, do not subclass UIButton, use custom factory method like this one.

Upvotes: 3

villy393
villy393

Reputation: 3083

Just use a plain button and cut your own corners:

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

Upvotes: 2

Alaeddine
Alaeddine

Reputation: 6212

You need to use UIButtonTypeSystem instead.

enter image description here

UIButton Class Reference

Upvotes: 1

Related Questions