Home Ask Login Register

Developers Planet

Your answer is one click away!

TamoDaleko February 2016

Set the position of a UILabel to center

I have a view on that view I have a button and a label but the label will not align to be in center why so ever, its always on the right hand side of the view ....

pic what constraints I have set


enter image description here


MANIAK_dobrii February 2016

Remove center X constraint, you have trailing/leading for that. After this your UILabel will be centered in the superview, but the text inside won't:

| [Text      ] | 

To center text, just set UILabel'stextAlignment to NSTextAlignmentCenter (centered), so it will be like:

| [   Text   ] | 

Also I suggest to remove forced height constraint (you have it set to 28) and replace it with something like top/bottom space or like that.

Post Status

Asked in February 2016
Viewed 2,805 times
Voted 7
Answered 1 times


Leave an answer

Quote of the day: live life