I need to put button image right after the text. Following some answers I found here on SoF, I have subclassed UIButton like the following:
class RightAlignedIconButton: UIButton {
override func titleRect(forContentRect contentRect: CGRect) -> CGRect {
var frame = super.titleRect(forContentRect: contentRect)
frame.origin.x = titleEdgeInsets.left
return frame
}
override func imageRect(forContentRect contentRect: CGRect) -> CGRect {
let titleRectangle = titleRect(forContentRect: contentRect)
var frame = super.imageRect(forContentRect: contentRect)
frame.origin.x = titleRectangle.origin.x + titleRectangle.width + imageEdgeInsets.left
return frame
}
}
The problem I experience is that when I change text with acceptanceStatusButton.setTitle("New text", for: .normal)
icon remains where it was despite text being longer/shorter (so sometimes I have icon right on top of new long text). How can I resolve this issue?