0

I am using Swift 3 and stack views (aka auto layout) with constraints.

At the moment my app's header and the standard iOS status bar is overlapping.

I DON'T want to create another empty stack with a fixed height because I'm trying to keep it as responsive as possible for now and the future (for iPhone 5 the height probably like 50px and iPhone 7 it is probably like 200px).

Is there some sort of logical solution from the interface, or is the only way to do it to load some custom code in the;

override func viewDidLoad() section?

Bista
  • 7,869
  • 3
  • 27
  • 55
Brewski
  • 654
  • 3
  • 14
  • 29

1 Answers1

0

You can apply NSLayoutConstraint:

1) Create an autolayout top leading constraint between super view and stack view - CTRL drag it to your view controller

@IBOutlet weak var topLeadingOffsetFromStatusBar: NSAutolayoutConstraint!

2) Set its constant to dynamic value:

let offset = UIApplication.sharedApplication().statusBarFrame.size.height
self.topLeadingOffsetFromStatusBar.constant = offset
pedrouan
  • 12,762
  • 3
  • 58
  • 74
  • That did not work unfortunately - the latest version of Xcode Version 8.0 (8A218a) and Swift 3 - changed the code slightly with updated keywords and built successfully but then it crashed with error: libc++abi.dylib: terminating with uncaught exception of type NSException – Brewski Sep 18 '16 at 11:37
  • I am using swift3 as well. I assumed you use swift2. Do you want me to retype the code to swift3 for you? – pedrouan Sep 18 '16 at 12:01
  • Aha, well I already did when it gave me the error: @IBOutlet weak var topLeadingOffsetFromStatusBar: NSLayoutConstraint! let offset = UIApplication.shared.statusBarFrame.size.height and then self.topLeadingOffsetFromStatusBar.constant = offset ,,.. in the viewDidLoad() – Brewski Sep 18 '16 at 13:29