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'
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With