Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

suclassing a UIButton of type .system

I am trying to subclass UIButton, but i want it to be of type .system. I am struggling with initializers

class FormButton: UIButton {

var type FormButtonType: FormButtomType.oneSelection

init(oftype formType: FormButtomType) {
    self.type = formType
    super.init(type: .system)
}

} 

problem is that I have the following error message : "Must call a designated initializer of the superclass 'UIButton'

like image 906
user3239711 Avatar asked Nov 08 '22 21:11

user3239711


1 Answers

You can't override a convenience method and call super convenience method... As an alternative you can do a static method that return a FormButton of UIButtonType.system type.

class FormButton: UIButton {
    class func newButton() -> FormButton {
        return FormButton.init(type: .system)
    }
}

Use it like this

let button = FormButton.newButton()
like image 72
Bilal Avatar answered Nov 14 '22 23:11

Bilal