I do have the problem that I got some crashes in iOS with a UILabel
subclass. Now I would like to override setText:
to call layoutIfNeeded
as this may solve the problem according to some stackoverflow-answers (e.g. this one).
But how can I achieve this? In Objective-C it was no big deal, but I don't find a way to override setText:
in Swift.
Override the property text
and provide code in didSet
which will get executed when the text
property is set:
class MyLabel: UILabel {
override public var text: String? {
didSet {
layoutIfNeeded()
}
}
}
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