title: iOS. Make a layout constraint to glue to status bar bottom + X regardless of navigation bar
body: <p>I have a bunch of view controllers with slightly different layouts but with the same requirement for a vertical position of a top UILabel. It has always be X(=70) units from status bar. These view controllers might be added to navigation controllers with navigation bars or not.</p>
  
  <p>How can I make a relatively generic layout constraint to account for navigation bar so my title is always X units from status bar regardless if the view controller is in navigation stack or not?</p>
  
  <p>(I know that I can change constants for existing constraints in runtime, but this might be a bit problematic with a lot of controllers with xibs. I am looking for something more generic preferably in interface builder)</p>
  
  <p>I am using iOS 11 SDK with Safe Area guides.</p>
  
  <p>Please see pictures for more clarity.</p>
  
  <ol>
  <li>Status bar only with X units to status bar. There is a constraint to top of Safe Area with constant X.</li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/fYvIK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fYvIK.png" alt="1.Status bar only"></a></p>
  
  <ol start="2">
  <li>Status bar + navigation bar. There is again a constraint to top of Safe Area but this time to get the result I wanted, I had to subtract navbar.height from X. constant X - navbar.height.</li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/GJXxN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GJXxN.png" alt="2. Status bar + navigation bar"></a></p>
  
  <p>Basically I look for something that will allow to automatically adjust constant of constraint depending on presence of navigation bar. Maybe there is a possibility to achieve this with a couple of constraints which are "easily" copiable from xib to xib.</p>