18
votes

I have a problem with the new navigation bar for iOS 11.

In root view set new navigation by code:

if (@available(iOS 11.0, *)) {
    self.navigationController.navigationBar.prefersLargeTitles = YES;
    self.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeAlways;
}

Then from root view, I pushed to another view and set code navigation bar by

if (@available(iOS 11.0, *)) {
    self.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeNever;
}

It works well. However, when push and pop view a black color appeared like the image below:

enter image description here

I don't know why the black color appeared on this view although I did not set back ground for navigation bar is a black color for the whole screen in my app.

Someone have any idea for the problem. Please drop me some suggestion to solve that bug. Thanks.

3
Show your AccountVC codeJay Patel

3 Answers

32
votes

I solved this issue by setting navigation controller background colour in the UIViewController class where I am getting black colour.

Here is the code I used :

navigationController?.view.backgroundColor = UIColor.white

I have tried changing background colours and shadows in story board but it doesn't seem to fix this issue. Hopefully this answer is still relevant here.

9
votes

I solved this in my own app by subclassing UINavigationController and setting its view.backgroundColor.

7
votes

I solved this issue with simple extension

extension UINavigationController {

    @IBInspectable var backgroundColor: UIColor {
        set {
            self.view.backgroundColor = newValue;
        }
        get {
            return self.view.backgroundColor ?? UIColor.black;
        }
    }

}

You can change background color from storyboard!