suclassing a UIButton of type .system

Viewed 1924

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'

4 Answers

I'm guessing that you need the System type because of the highlighted animation behaviour. If so, You can override the Highlighted property in your UIButton subclass like so:

var isHighlighted: Bool {
        didSet {
            // If you have images in your button, add them here same as the code below
            (self.isHighlighted && self.titleLabel != nil) ? (self.titleLabel!.alpha = 0.2) : (self.titleLabel!.alpha = 1.0)
        }
    } 
Related