I want to subclass UIButton
and add to it a property isActive
, which is a Bool
that changes the look of the button (this is not related to the default .enabled
property).
However, I also want to set the button type when initialized. Specifically, I want to initialize it much like it is in UIButton
, like:
let button = MyButton(type: .Custom)
However, because the .buttonType
is a read-only, I cannot just override it like:
convenience init(type buttonType: UIButtonType) {
buttonType = buttonType
self.init()
}
This spits out an error: Cannot assign to value: 'buttonType' is a 'let' constant
(I already implemented the required init(coder:)
).
So how can I set the .buttonType
when initialized?
NOTE: The custom property shall be also used in other functions to change the logic within it, so I picked up a property, instead of defining two functions to change the look.