Arbitur Arbitur - 3 months ago 18x
iOS Question

Autolayout: Add constraint to superview and not Top Layout Guide?

I have a UIView in my UIViewController in storyboard which I want to add a constraint on to space that view a distance from the top edge.

Now, when I do the usual by ctrl + drag to the ViewController's main view I only get option to set it to top layout guide.

This is a problem for me because at one point in the app Im going to move the main view up around 20-50px and what happens then is that view I have will not move... because its not aligned to superview.

How can I manually do this in storyboard or do I have to add it programatically?

Im using xcode 6.

dan dan

You should be able to do it by highlighting the view you want in the storyboard and then selecting Editor > Pin > Top Space to Superview in the top menu.

This is outdated in XCode 7, see @PaulGurov's answer instead.