问题
How can I implement auto layout for multiple label as shown in image
I need to maintain relative equal spacing between all label and side space too. I want to maintain equal spacing between label 1,2,3,4. I am unable to maintain relative equal spacing between the labels for multiple iPhone versions using AutoLayout.
I was able to solve using following steps:
Step1: Place the label or button you want to create inside a view and give that view constraint as below:
Step2: Select all the label or button you want to create and set constraint as below:
At First
At Second
At third
回答1:
Try this to get equal spacing between various labels,
label1.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
label2.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
label3.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
label4.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
回答2:
Check this out you can find it helpful
http://effortlesscode.com/evenly-spacing-views-auto-layout/
回答3:
Update:
This is now an outdated answer. Also, the link referred to is no longer live. Instead, check Apples Autolayout guide.
Original Answer:
Apple has an excellent example and explanation of the problem that you are facing. You can find the solution here.
They use auxiliary views for spacing called spacer views between the visible views.
Hope it helps. :)
来源:https://stackoverflow.com/questions/29789961/how-to-create-equal-spacing-between-multiple-label-in-ios-xcode-6-3-using-autola