Reputation: 1026
I am tried to remove the navigation bar background in iOS 13 in the if's statements with #available. I know the original code to remove the navigation bar background for iOS 12 and older iOS in the else's statements. However, Apple did announce a new system called Appearance in anywhere to support that new iOS 13 system.
let app = UINavigationBarAppearance()
let navigationBar = self.navigationController?.navigationBar
app.configureWithOpaqueBackground()
app.shadowImage = UIImage()
self.navigationController?.navigationBar.scrollEdgeAppearance = app
navigationBar!.standardAppearance = app
navigationBar!.scrollEdgeAppearance = app
I believe this configureWithOpaqueBackground() allows us to remove the navigation bar background, But I test on iOS 13.1 simulator appear black navigation bar background. I know what caused it.
app.configureWithOpaqueBackground()
app.titleTextAttributes = [.foregroundColor: UIColor.white]
app.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
app.backgroundColor = #colorLiteral(red: 0.1603881121, green: 0.1677560508, blue: 0.2133775949, alpha: 1)
That code allows us to put the custom color on the black background. I ready to add that code in the viewWillDisappear's statements to restore the navigation bar background to normal color background before self.navigationController?.navigationBar.scrollEdgeAppearance = app
with remove app.configureWithOpaqueBackground()
and app.shadowImage = UIImage()
. Now, I need to create the translucent navigation bar background in the viewWillAppear's statements, but it can't see any translucent background due to the black background still display.
I really appreciate your help in resolving the problem! :)
Upvotes: 0
Views: 3242
Reputation: 535306
If you want the navigation bar to become completely transparent:
let app = UINavigationBarAppearance()
app.configureWithTransparentBackground()
self.navigationController?.navigationBar.standardAppearance = app
self.navigationController?.navigationBar.scrollEdgeAppearance = app
self.navigationController?.navigationBar.compactAppearance = app
Do not mess with the isTranslucent
of the navigation bar.
Upvotes: 7