GO FURTHER, FASTER: Try the Swift Career Accelerator 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?

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 try! Swift Tokyo.

SPONSORED Ready to dive into the world of Swift? try! Swift Tokyo is the premier iOS developer conference will be happened in April 9th-11th, where you can learn from industry experts, connect with fellow developers, and explore the latest in Swift and iOS development. Don’t miss out on this opportunity to level up your skills and be part of the Swift community!

Get your ticket here

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.