UINavigationBar background Image - broken in iOS 11?

The following code worked just fine for setting a custom image as a UINavigationBar background:

    // In AppDelegate.swift: 
    let image = UIImage(named:"HeaderBanner-new")
    UINavigationBar.appearance().setBackgroundImage(image, for: UIBarMetrics.defaultPrompt)

Since upgrading to Xcode 9, Swift 4, and iOS 11, this code no longer works. All I get is a plain white background in a UINavigationBar.

I also tried moving the code from AppDelegate.swiftand putting it directly into my own custom file UINavgiationController.swift:

    let image = UIImage(named:"HeaderBanner-new")
    self.navigationBar.setBackgroundImage(image, for: UIBarMetrics.defaultPrompt)

Still not working. Any ideas what is going on - or ideas for a workaround / hack?

+4
source share
1 answer

It seems that NavigationBar.setBackgroundImage is not working properly in iOS 11.

​​ NavigationBar.barTintColor, .

.

+1

Source: https://habr.com/ru/post/1687575/


All Articles