Another way to say it is how can I position a UILabel so the space above it equals one half of the space below it. I'd prefer to do this in a storyboard or xib file.
Asked
Active
Viewed 1,149 times
2
-
This question/answer may help: http://stackoverflow.com/questions/14935825/autolayout-make-height-of-view-relative-to-half-superview-height – Firo Jan 28 '15 at 22:04
1 Answers
4
Connect a constraint from the bottom of the label to the bottom of the superview. Edit that constraint and set it so that the first item is the label and the second item is the superview. Set the constant to 0
and the multiplier to 1/3
.
You can tweak that 1/3
to whatever you need to get the results you want. I find it often useful to place the view how I want it to look, see what it's y
value is and then use that divided by the height of the superview as the multiplier. So, say you want it at y=20
when the height is 60
, you'd put 20/60
as the multiplier. (Yes, that's the same as 1/3
in this case, but I often have cases like 83/221
etc).

Dave Wood
- 13,143
- 2
- 59
- 67
-
I thought I had finally gotten the hang of constraints but actually I didn't understand the "constant" and "multiplier" fields until now. I made a little demo app and fiddled with the values and now it seems clear. Many thanks. – RobertL Jan 29 '15 at 18:00