KikX
KikX

Reputation: 217

Align both image and UILabel of the UIButton in the left

I currently have :
enter image description here

using this code:

button.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
button.transform = CGAffineTransformMakeScale(-1.0, 1.0);
button.titleLabel.transform = CGAffineTransformMakeScale(-1.0, 1.0);
button.imageView.transform = CGAffineTransformMakeScale(-1.0, 1.0);

What I'm trying to achieve is this:
enter image description here

Where the image and UILabel should be on the left side of the UIButton, not in the middle.

Upvotes: 1

Views: 251

Answers (2)

Shilpriya
Shilpriya

Reputation: 91

To done this in Interface Builder you just need to change "alignment" property....

1.In attribute inspector of button change alignment Property to first option

enter image description here

2. this will be your output

enter image description here

3.if you want some space between image and title you can give from size inspector (just give some space in left property of title insets)

enter image description here

4.Final Output

enter image description here

Upvotes: 0

Abhijit
Abhijit

Reputation: 392

Try contentHorizontalAlignment property.

Objective-C

button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;

Swift

button.contentHorizontalAlignment = .left

Upvotes: 2

Related Questions