JiteshW
JiteshW

Reputation: 2205

Adding multiple UILabels in view with constant height between them

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:))

Upvotes: 2

Views: 122

Answers (3)

Vijay Sharma
Vijay Sharma

Reputation: 1076

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)

Upvotes: 1

Mert Buran
Mert Buran

Reputation: 3017

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+

Upvotes: 1

prema janoti
prema janoti

Reputation: 169

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.

Upvotes: 0

Related Questions