NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

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?

1      

        // 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.

1      

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.

1      

I put this on appear modiflier on first view

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

1      

Hacking with Swift is sponsored by Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

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.