Ios- Autolayout - add a constraint for a navigation item

I just started porting my application to autorun. I want to limit the label “0” below the navigation bar. I tried, but could not find a solution. Here are the screenshots.

In the storyboard, I gave a restriction from the supervisor.

enter image description here

In iOS7, it works great.

enter image description here

But in iOS6, it goes beyond the navigation bar by 64 pixels, as the add-in starts below the navigation bar.

enter image description here

If I could add an upper limit for the label below the navigation bar, this will solve the problem. But I can not find how to do it. I looked through a few questions. but got an answer.

Please, help.

+8
ios autolayout
source share
2 answers

Update for iOS 11:

IOS 11 introduces the concept of safe areas, and the burden of the container - all the content in the visible area, again, is in the hands of the view, not the tango of vision and the controller.

See Apple documentation here .

When working with a drop-down database or XIB, it is as simple as including a function in Xcode. This is backward compatible and should work as expected in iOS 10 and below. In the code, you should use if (@available(iOS 11.0, *)) to decide whether to set limits on safe direction / area bindings or use outdated manuals for older systems.


When using storyboards, you need to add a limit to the layout guide . This will take care of your problems, since on iOS6, i.e. 0pt and on iOS7, it is dynamic. If you use the nib / xib file, it becomes a little more complex; you need to add a restriction to the code. The easiest way to achieve this is to create a constraint with 0 vertical space up, create an output for this constraint in the code and in viewDidLayoutSubviews , update the constant output limit line to self.topLayoutGuide.length .

+9
source share

You just need to make some changes to your restrictions:

1) Give a height limit to your label

2) Connect the shortcut to the master view - Horizontal spatial restriction

3) Add Vertical Spatial Constraint

The third step should be careful [I am attaching an image for reference.]

Adding vertical space constraint

And after that, check if the red arrow is saved on your view controller.

0
source share

All Articles