Tinting navigation bars and tab bars in iOS 15
It was never really simple to set the background colour of
UITabBar. The most common way is to set the colour on their appearance proxies at startup time, e.g. in
UITabBar.appearance().barTintColor = UIColor.red UINavigationBar.appearance().barTintColor = UIColor.red
Even with the arrival of SwiftUI this did not get any better. Even though there are "new" views
TabView, they are backed up by
UITabBar and there is no API to set their background colour, so you still need to set the colour on the appearance proxy.
However in iOS 15 this hack no longer works! You now have to use the
UIBarAppearance introduced in iOS 13, and its subclasses
Here is an example for setting the background colour of the navigation bar.
let navigationBarAppearance = UINavigationBarAppearance() navigationBarAppearance.configureWithOpaqueBackground() navigationBarAppearance.backgroundColor = UIColor.red UINavigationBar.appearance().standardAppearance = navigationBarAppearance UINavigationBar.appearance().scrollEdgeAppearance = navigationBarAppearance
Let's hope Apple exposes a nice SwiftUI API to do this soon.