2

I am trying to add some 5-6 UILabel's (Single line only) in a UIView using auto layouts. I have added constraints for top most & bottom most UILabel. The problem is variable screen sizes.

Just wants to know a better approach of adding those remaing (3-4) middle UILables (As I want to show equal space between all the UILabels).

Approach 1 - Add height constarint for middle lables & based on screen size change the height constraint constat at runtime.

Approach 2 - I tried adding >= and <= constarints but I am not getting the output as desired.

Any help, how can I keep constant height between all UILabels.

(Can be achieved via UIScrollView or UITableView but I dont want scrolling .. only using auto layouts:))

JiteshW
  • 2,195
  • 4
  • 32
  • 61

3 Answers3

1

You can add dummy UIViews between your UILabels and set those dummy views' heights to proportional to their container. Or you should be able to achieve that by setting your current constraints constants at runtime and then calling setNeedsLayout&layoutIfNeeded

You can't achieve that by playing with "less than" or "greater than" constraints.

Edit: You can also use UILayoutGuide to do that on iOS9.0+

Mert Buran
  • 2,989
  • 2
  • 22
  • 34
  • Changing constraints at runtimes looks easy to me. But I didn't get "set those dummy views heights to proportional to their containers" part. Can you explain a bit. – JiteshW Aug 31 '15 at 17:09
1

You can use stack view from left window where you have button/label/view etc..... or also you can add it from constraints tools(see attached imageenter image description here)

Vijay Sharma
  • 1,046
  • 9
  • 19
0

iPhone 5s

iPhone 6 plus

If you are looking for the attached solution, please add below constraints shown in the third image.

Note * you can change the constant value as per your requirement.

prema janoti
  • 159
  • 1
  • 4