質問

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.

役に立ちましたか?

解決

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.

他のヒント

You just have to make some modifications in your constraints :

1) Give a height constraint to your label

2) Pin your label to leading view - Horizontal Space Constraint

3) Add a Vertical Space Constraint

3rd step has to be careful [I'm attaching an image for your reference.]

Adding Vertical Space Constraint

And after doing that, check if the red arrow mark still persist on your View Controller.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top