Wednesday, March 6, 2013

How to make UIButton text left (or right) aligned?

It's a really common question and the answer is:

[button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];

Of course, there is also:

[[button titleLabel] setTextAlignment:NSTextAlignmentLeft];

The difference is that the first method sets alignment of the button content, and the second one sets the alignment of the text in the label. But the label frame is as wide as the text is. So if the label has only 1 line, it will always be centered.

2 comments:

  1. Good day! I was so impressed to see a very well-presented dishes that is absolutely tasty and delicious. You've done a great job.Well, thank you for sharing your talent and article it is very well appreciated. You can also visit my site if you have time.

    n8fan.net

    www.n8fan.net

    ReplyDelete
  2. Thanks! Simple and right on the target.

    ReplyDelete