Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios- Autolayout- add constraint respect to navigation item

Tags:

ios

autolayout

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.

enter image description here

In IOS7 it works fine.

enter image description here

But in IOS6 it goes below navigation bar by 64 pixels, as superview starts below navigation bar.

enter image description here

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.

like image 320
Durgaprasad Avatar asked Apr 29 '14 13:04

Durgaprasad


1 Answers

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.

like image 87
Léo Natan Avatar answered Nov 02 '22 23:11

Léo Natan