Reputation: 2155
Now I want to alignment the text of button to the left with code , how to do ? and I code this :
button.titleLabel.textAlignment = UITextAlignmentLeft;
but it doesn't work.
Upvotes: 41
Views: 30877
Reputation: 258
Setting to button titleLable alignment also works perfectly.
btn.titleLabel.textAlignment=NSTextAlignmentCenter;
Upvotes: 0
Reputation: 17007
For those who are using Swift 3
button.contentHorizontalAlignment = .left
Above code align text to left border, so you might want little padding.
button.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0)
Upvotes: 2
Reputation: 1043
Use ContentHorizontalAlignment
as below
btnObj.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
Upvotes: 26
Reputation: 1978
Swift Code
button.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Left
Upvotes: 9
Reputation: 10621
You have to use contentVerticalAlignment
and contentHorizontalAlignment
of the button.
Upvotes: 79