问题
I am using auto layout in storyboard with all resolution support,but I am stuck on one thing that.I want flexible horizontal spacing between my labels using constraints.Please see screenshot for more details. This is a 4.7inch screen.This screen is correct as I designed for particularly this screen
4 inch screen
5.5 inch
IPad screen
Please help to manage my labels spacing equally in all supported resolutions with auto layout and constraints.
Edit
This is my view hierarchy and it is also a subview of some view controller's view.
回答1:
You have 5 views containing labels. Let's call those view1
through view5
and let's call their super view orangeView
.
Start by laying out the
orangeView
. Constrain its leading edge to the leading edge of its super view. Constrain its trailing edge to the trailing edge of its super view. Constrain its height to 50.Add 5 more views as subviews of
orangeView
. Lay them out visually approximately as you want them to be.Starting with the leftmost view, which we'll call
view1
, constrain its top edge to be 8 points from the top edge of it nearest neighbor (which is theorangeView
's top). Constrain its bottom edge to 8 points from the bottom edge oforangeView
. Constrain its left edge to be 8 points from its nearest neighbor. Repeat this for views2
through4
, always constraining their top, left, and bottom edges to be 8 points from the nearest neighbor. Forview5
, constrain all 4 edges to be 8 points from the nearest neighbor.Constrain
view2
's width to be equal toview1
's width. Constrainview3
's width to be equal toview2
's width. Constrainview4
's width to be equal toview3
's width. Constrainview5
's width to be equal toview4
's width. This is what enables all of the views to grow together in size.Add a label as a subview to each of views
view1
throughview5
. Constrain their widths and heights to be big enough to hold your text. Add 2 constraints to each label to center it vertically and horizontally in its containing view.
来源:https://stackoverflow.com/questions/27665931/flexible-horizontal-spacing-between-ui-labels