How to create equal spacing between multiple label in ios xcode 6.3 using AutoLayout Constraints

两盒软妹~` 提交于 2020-01-02 09:27:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!