Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS layout why does center constraint not enough?

Tags:

ios

I really don't understand the logic of this ... well ... strange iOS layout system.

I place a UILabel with the constraint Align center X to Superview.

Why does it complain to need a new constraint for X position ??

center is center no?

like image 343
fralbo Avatar asked Sep 19 '14 12:09

fralbo


1 Answers

You need to tell more about the horizontal positioning of the view. Centering the view does not say wether it has a fixed width or it should keep the leading / trailing space around view.

Here are two possible options (there is also a fixed height with a fixed aspect ratio, as @Moshe said in his answer):

  1. Your view will always have a width of 61 (for example):

Fixed width

  1. Your view will have a fixed leading and trailing space on the left/right side:

Leading / trailing

like image 136
rdurand Avatar answered Oct 27 '22 07:10

rdurand