I have a UIButton
with text \"Explore the app\" and UIImage
(>)
In Interface Builder
it looks like:
[ (>) Explore t
Forcing 'right-to-left' for the button is not an option if your app supports both 'left-to-right' and 'right-to-left'.
The solution that worked for me is a subclass that can be added to the button in the Storyboard and works well with constraints (tested in iOS 11):
class ButtonWithImageAtEnd: UIButton {
override func layoutSubviews() {
super.layoutSubviews()
if let imageView = imageView, let titleLabel = titleLabel {
let padding: CGFloat = 15
imageEdgeInsets = UIEdgeInsets(top: 5, left: titleLabel.frame.size.width+padding, bottom: 5, right: -titleLabel.frame.size.width-padding)
titleEdgeInsets = UIEdgeInsets(top: 0, left: -imageView.frame.width, bottom: 0, right: imageView.frame.width)
}
}
}
Where 'padding' would be the space between the title and the image.