UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Fix NavBar in Sheet with ScrollView?

Forums > SwiftUI

I have a NavigationView that loads via sheet. THe Sheet has a ScrollView in it. When the user scrolls the NavBar changes background color. I am not sure if this is a bug or not?

I am using Xcode 13 and using iOS 15

Here is a quick video showing the issue.

Any ideas on how to fix this?

3      

        // Set top Nav Bar behavior for ALL of app
    let standardAppearance = UINavigationBarAppearance()

    // Title font color
    standardAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]

    // prevent Nav Bar color change on scroll view push behind NavBar
    standardAppearance.configureWithOpaqueBackground()
    standardAppearance.backgroundColor = UIColor.blue

    self.navigationController?.navigationBar.standardAppearance = standardAppearance
    self.navigationController?.navigationBar.scrollEdgeAppearance = standardAppearance

You need to set the 'scrollEdgeAppearance' object to be the same as the 'standardAppearance' object you show above. Set it in the 'veiwDidLoad' of your ViewController.

3      

Or, since this is SwiftUI, do it in your View's init or even in your App struct's init.

To add a bit more detail, this is the way navigation bars now work in iOS 15. Lots of people have had issues with this.

3      

I put this on appear modiflier on first view

.onAppear {
  if #available(iOS 15.0, *) {
      let tabBarAppearance = UITabBarAppearance()
      tabBarAppearance.configureWithOpaqueBackground()
      UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
  }
}

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.