简体   繁体   中英

How to remove white space on top of my navigation bar? (swift)

I made an apps with only using XIB (without storyboard). so to navigate I'm using this code to push some of the views:

let vc = SecondViewController()
self.navigationController?.pushViewController(vc, animated: true)

I already make the first vc as rootvc, so it automatically created navigation bar for me.

the problem is the navigation bar generated not at top of the screen and leaving some white space gap. So here is the image when I'm using large title

在此处输入图像描述

and here is the normal one

在此处输入图像描述

I have tried to run it without safe area layout as well. what happened is the navbar stayed there but the view goes up (through behind navbar).

navigationController.isNavigationBarHidden = true

Try adding this line to your code for hide default navigation bar.

I've experienced this kind of problem, too.

There are many ways to remove white space.

I want to help you this way.

Add UIView above navigation Bar. 在此处输入图像描述




and then, Fix UIView Top constraint. 在此处输入图像描述

and change UIView Color. 在此处输入图像描述

this is result.

在此处输入图像描述

Again, there are many ways...

Use this in your view controller's class:

navigationController?.setNavigationBarHidden(true, animated: animated)

在此处输入图像描述

you can change your status bar colour by using. i don't remember the code but from here you can also can also change your colour in two Default styles

and use this to hide and show your navigation bar //code navigationController.isNavigationBarHidden = true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM