2

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?

nhgrif
  • 61,578
  • 25
  • 134
  • 173
Ryan Kreager
  • 3,571
  • 1
  • 20
  • 35
  • 2
    I can't imagine this is *actually* Swift specific. I'm pretty sure that button type was deprecated in iOS7. – nhgrif Jul 20 '15 at 16:25
  • Right you are sir - it turns out it's not Swift specific, I just happened upon it during a swift migration for an app. #hattip – Ryan Kreager Jul 20 '15 at 16:34

3 Answers3

3

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.

Community
  • 1
  • 1
zrzka
  • 20,249
  • 5
  • 47
  • 73
2

Just use a plain button and cut your own corners:

let button = UIButton()
button.layer.cornerRadius = 3.0
button.clipsToBounds = true
villy393
  • 2,985
  • 20
  • 28
1

You need to use UIButtonTypeSystem instead.

enter image description here

UIButton Class Reference

Alaeddine
  • 6,104
  • 3
  • 28
  • 45