I would like to add a white space in front of any given text of a UILabel.
I thought that I could extend the UILabel-class as follows:
class UILabel_iKK: UILabel {
override var text: String? {
didSet {
if let txt = self.text {
self.text = " " + txt
}
}
}
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
But obviously this leads to an endless loop (i.e. text change causes didSet to fire again and again.
What would be another way of doing this in a most elegant way ?