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;
Setting to button titleLable alignment also works perfectly.
btn.titleLabel.textAlignment=NSTextAlignmentCenter;
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)
You have to use contentVerticalAlignment
and contentHorizontalAlignment
of the button.
Use ContentHorizontalAlignment
as below
btnObj.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
Swift Code
button.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Left