Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align button image to right edge of UIButton

There are plenty of threads about aligning a button image according to the title text, but I can't find anything about just aligning the image to the right side of the button.

This has no effect:

button.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 50);

How can one right-align the image for a button? Can it be done in the Storyboard?

like image 705
soleil Avatar asked Sep 02 '25 05:09

soleil


2 Answers

Semantic: Force Right-to-Left on View works for me enter image description here

like image 197
Gilad Brunfman Avatar answered Sep 04 '25 22:09

Gilad Brunfman


I found a tricky way Update the constrains for the UIImageView of the Button

try this

button.imageView?.trailingAnchor.constraint(equalTo: button.trailingAnchor, constant: -8.0).isActive = true
button.imageView?.centerYAnchor.constraint(equalTo: button.centerYAnchor, constant: 0.0).isActive = true

but don't forget to add this to make the constrains effective

button.translatesAutoresizingMaskIntoConstraints = false
button.imageView?.translatesAutoresizingMaskIntoConstraints = false
like image 24
Simon K. Gerges Avatar answered Sep 04 '25 23:09

Simon K. Gerges