Unable to set UIButton buttonType in initializer in Swift

I want to subclass UIButton in Swift. I get an error while setting upbuttonType

class MyButton: UIButton {

    init(label: KeyLabelType) {

        super.init(frame: CGRectZero)

        self.buttonType = UIButtonType.Custom
    }
}

Any suggestions on why this is wrong?

+4
source share
1 answer

Apple documents say it buttonTypeis a readonly property. You will need to find a workaround for this. This answer can give you what you are looking for.

+4
source

Source: https://habr.com/ru/post/1543754/


All Articles