Reputation: 3184
Ok, we have 4 (2,3 or 5) label in storyboard like in attached picture. I need to evenly centered all items for all devices (vertical and horizontal orientations).
I can't right options for constrains, I spent a lot of time as well as the saw many tutorials, but in all examples not used size classes for this.
I know I must use multiplier, but I don't understand how?
Thx.
Upvotes: 0
Views: 139
Reputation: 20187
Let's assume the case of four labels. You need to create three separate sets of constraints: the first will make the labels 1/4 of the width of the screen, the second will position them evenly within their containing view, and the third will make sure the containing view fills the full screen width, whatever that is. You set these constraints on the "All, All" size class so they will apply everywhere.
1) Create a constraint that makes the width of each label "Equal" to the width of the containing view. In this constraint, set the multiplier to 0.25. This will then make the label 25% of the width of the containing view.
2) Set the position of the first label by a constraint that keeps its left edge the same as the left edge of the containing view. For each of the other labels, set a constraint that keeps their left edge next to the right edge of the previous label.
3) Set constraints on the containing view to keep both left and right edges equal to the left and right edges of its own containing view.
Finally, centre the label text within each of the label frames just using the usual text alignment tools (not related to autolayout).
Upvotes: 1