0

I have an iOS app coded in Swift and using storyboards. There's a "header bar" at the top of the view controller in the storyboard that should be flush with the left/right edges of the phone:

According to storyboard + autolayout, no gap between edge and header

This behaves as expected in iPhone 6s. However, in the iPhone 7 Plus, it somehow shows a tap of maybe 2 millimeters on the screen, as if the autolayout does not work. According to autolayout, the leading space is -16. Setting it to 0 does not fix it.

autolayout constraints for left edge

Is there something I'm missing on autolayout that makes it work on all devices without showing gaps?

Uzumaki Naruto
  • 547
  • 5
  • 18
  • Are there any ambiguous / conflicting constraints ? Take a backup remove all constraints for the view with the super view and add them one by one. – user1046037 Sep 18 '17 at 13:51
  • 2
    This is a bad way to give the constraint. You have given the constraint to the margin instead of the edge of the screen. Hence, it works fine in 6s but not in any plus device. Remove the constraint and re-apply them with `Constraints to margin` OFF. – Aju Antony Sep 18 '17 at 13:58
  • Let me know if it works, I'll make this an answer :D – Aju Antony Sep 18 '17 at 13:59
  • 2
    And ya one more thing, when you give constraints with `Constraints to margin` off, make sure you give the constant as 0.0 instead of -/+16.0 – Aju Antony Sep 18 '17 at 14:00
  • thanks! will give these a try, folks... – Uzumaki Naruto Sep 18 '17 at 15:58
  • @CoderFrom94 - it works! That is *precisely* the problem. Please note -- I didn't have to delete the constraint...merely remove the "relative to margin" in the Size Inspector at the top right and then set the constant to 0, after clicking on the constraint in the Documents Outline – Uzumaki Naruto Sep 18 '17 at 16:10
  • Alrighty, I'll make it an answer then :D – Aju Antony Sep 19 '17 at 01:27
  • @UzumakiNaruto which xcode version are you using, I am trying to find the relative to margin option and I swear that it's almost impossible to find. – Aju Antony Sep 19 '17 at 01:31
  • It's the latest version of Xcode. You have to highlight the constraint first in the Documents Outline and then go to the Size Inspector on the top right...dropdown menu will let you see it. – Uzumaki Naruto Sep 20 '17 at 09:37

1 Answers1

1

This is a bad way to give the constraint. You have given the constraint to the margin instead of the edge of the screen. Hence, it works fine in 6s but not in any plus device. Remove the constraint and re-apply them with Constraints to margin OFF.

And ya one more thing, when you give constraints with Constraints to margin off, make sure you give the constant as 0.0 instead of -/+16.0

Aju Antony
  • 639
  • 6
  • 13