Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 11 Navigation bar large title have black color when push on pop view controller

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.

like image 730
Cuong Nguyen Avatar asked Jul 26 '17 08:07

Cuong Nguyen


People also ask

How do I change my Apple navigation bar?

On your Mac, use Dock & Menu Bar System Preferences to change the appearance of the Dock, and to select items to show in the menu bar and in Control Center. To change these preferences, choose Apple menu > System Preferences, then click Dock & Menu Bar .

Can you change the navigation bar on Iphone?

Change the Bar StyleA user changes the navigation bar's style, or UIBarStyle , by tapping the “Style” button to the left of the main page. This button opens an action sheet where users can change the background's appearance to default, black-opaque, or black- translucent.

What is Scrolledgeappearance?

The appearance settings for the navigation bar when the edge of scrollable content aligns with the edge of the navigation bar. iOS 13.0+ iPadOS 13.0+ Mac Catalyst 13.1+ tvOS 13.0+


2 Answers

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.

like image 114
Sasi Kanth Avatar answered Nov 15 '22 15:11

Sasi Kanth


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

like image 30
cookednick Avatar answered Nov 15 '22 15:11

cookednick