Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton center horizontally with word-wrap

I have two UIButtons in container (UIView). Both of them have the same options (except button title) :

UIButton's options

But when I launch this app on iPhone 5S I get result as below :

UIButtons on iPhone 5S

My question is : Why first button have horizontally centered text and second doesn't ? I want both of them to center their titles horizontally.

Greetings, Paweł

like image 350
Pawel Urban Avatar asked Feb 17 '15 11:02

Pawel Urban


1 Answers

Actually you first button is centered only because it has shorter words in the title. If you set the title from the second button to the first button, you will se the same result.

You need to set text alignment through the code to make the title centered:

 [button.titleLabel setTextAlignment: NSTextAlignmentCenter];
like image 168
Vladimir K Avatar answered Oct 27 '22 23:10

Vladimir K