Search code examples
xcodexcode-storyboard

Control constraint in storyboard


I have two controls in the storyboard, named xLabel and yLabel

yLabel can be anywhere on screen. xLabel is 50 above yLabel, and right aligned with the yLabel

In other word, x and y position of xLabel is dependence on yLabel. How can i set the constraint in xLabel? Is it possible to do this?

Thanks


Solution

  • yLabel can be any where on screen

    No, it can't. You must supply constraints that position it unambiguously.

    xLabel is 50 above yLabel, and right align with the yLabel. Is it possible to do this?

    Certainly. Pin the bottom of xLabel to the top of yLabel with a constant of 50, and pin the right edge of xLabel to the right edge of yLabel with a constant of 0.