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.

4 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
  3. Good post. I learn one thing tougher on different blogs everyday. It can always be stimulating to learn content material from different writers and apply somewhat one thing from their store. I’d choose to make use of some with the content on my blog whether or not you don’t mind. Natually I’ll offer you a link on your net blog. Thanks for sharing. casino bonus

    ReplyDelete
  4. I have read this post. Collection of post is a nice one ios swift online training

    ReplyDelete