I have a UIButton
with text "Explore the app" and UIImage
(>)
In Interface Builder
it looks like:
[ (>) Explore the app ]
But I need to place this UIImage
AFTER the text:
[ Explore the app (>) ]
How can I move the UIImage
to the right?
Here is my own way to do the thing, (after about 10 years)
class CustomButton: Button {
var didLayout: Bool = false // The code must be called only once
override func layoutSubviews() {
super.layoutSubviews()
if !didLayout, let imageView = imageView, let titleLabel = titleLabel {
didLayout = true
let stack = UIStackView(arrangedSubviews: [titleLabel, imageView])
addSubview(stack)
stack.edgesToSuperview() // I use TinyConstraints library. You could handle the constraints directly
stack.axis = .horizontal
}
}
}