0

I have problem with changing navigation bar color in iOS 15. In AppDelegate I'm setting UINavigationBarAppearence like this:

let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.shadowImage = UIImage()
appearance.shadowColor = .clear
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance

In my application, I need to change navigation bar color in multiple places in multiple colors.

Previously, just setting self.navigationController?.navigationBar.barTintColor = .yellow

did the trick but not anymore. Every time when I need to change navigation bar color, do I need to change whole UINavigationBarAppearence class attributes? If yes, it seems like a bit overload. But I cannot find better solution. Others methods like

self.navigationItem.setHidesBackButton(true, animated: true)

dont work anymore too. Instead

self.navigationController?.navigationBar.topItem?.setHidesBackButton(true, animated: true) 

only works. All these change just seems very confusing.

Dilan
  • 2,610
  • 7
  • 23
  • 33
  • can you attach some pic you have expected? – Maziar Saadatfar Mar 10 '22 at 15:56
  • "Every time when I need to change navigation bar color, do I need to change whole UINavigationBarAppearence class attributes" Basically yes, but you can apply them to `navigationItem` of a single view controller. – matt Mar 11 '22 at 04:26
  • @matt can you share some code? For example, for changing bar color. – user9417995 Mar 11 '22 at 10:31
  • I don't see how to make it clearer. Make another UINavigationBarAppearance and say `navigationItem.standardAppearance = ...` The bar color is the appearance's `backgroundColor`. – matt Mar 11 '22 at 10:38
  • And whats the best approach to change navigation bar title? – user9417995 Mar 14 '22 at 08:39

0 Answers0