BLACK FRIDAY: Save 50% on all my Swift books and bundles! >>

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      

Save 50% in my WWDC sale.

SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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.