I have just started to move my application to autolayout. I want to give constraint to a label '0' pixel below navigation bar. I tried but did not found solution. Here are screen shots.
In storyboard I gave constraint from superview.
In IOS7 it works fine.
But in IOS6 it goes below navigation bar by 64 pixels, as superview starts below navigation bar.
If I could add top constraint for label below navigation bar it will solve the problem. But I cant find how to do it. I searched through few questions. but dint got the answer.
Please help.
Update for iOS 11:
iOS 11 introduces the concept of safe areas, and the burden of container all the content in a visible area is, again, at the hands of the view, rather than a tango of view and controller.
See Apple's documentation here.
When working with storyboards or XIBs, it's as simple as enabling the feature in Xcode. This is backward compatible and should work as expected under iOS 10 and below. In code, you would use if (@available(iOS 11.0, *))
in order to decide whether to set constraints against the safe area guide/anchors or use the legacy guides on older systems.
When using storyboards, you need to add a constraint to the top layout guide. This will take care of your issues, as on iOS6, that is 0pt and on iOS7, it is dynamic. If you are using a nib/xib file, it gets a little more complicated; you need to add the constraint in code. The easiest way to achieve this is to create a constraint with 0 vertical space to top, create an outlet to this constraint in the code and in viewDidLayoutSubviews
, update the constant
of the constraint outlet to the value of self.topLayoutGuide.length
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With