Search code examples
iosswiftxcodeuinavigationbar

Navigation Bar colides with status bar in swift xcode for iphone 8 simulator


I'm working on an iphone app that will be compatible from iphone 6 to the new iphone. During the process, I've come to a problem where for iphone 8 simulator, the navigation bar's height is too short so the back button overlaps with status bar where in iphone 11, everything looks just fine. How would I go about in fixing this? How would I make the navigation bar look like the one shown in iphone 11? p.s. I've done nothing but link to show the current page when the user presses the button from the previous page. And, of course, I go back when i click on the back button.enter image description here


Solution

  • In your AppDelegate file you can add this:

     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        {
          //(by default it is True)
          UINavigationBar.appearance().isTranslucent = false
          // it will prevent overlaping
        }
    

    Apple Docs

    OR you can add this code in your viewController

    self.edgesForExtendedLayout = UIRectEdge(rawValue: 0)