Reputation: 2205
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
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 image)
Upvotes: 1
Reputation: 3017
You can add dummy UIView
s between your UILabel
s 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
Reputation: 169
If you are looking for the attached solution, please add below constraints shown in the third image.
Upvotes: 0