Skip to content

Instantly share code, notes, and snippets.

@molcik
Created March 10, 2020 12:25
Show Gist options
  • Save molcik/9958bb69836a2153006989025a9f39f8 to your computer and use it in GitHub Desktop.
Save molcik/9958bb69836a2153006989025a9f39f8 to your computer and use it in GitHub Desktop.
struct NavigationBarModifier: ViewModifier {
var backgroundColor: UIColor?
init( backgroundColor: UIColor?) {
self.backgroundColor = backgroundColor
let coloredAppearance = UINavigationBarAppearance()
coloredAppearance.configureWithTransparentBackground()
coloredAppearance.backgroundColor = .clear
coloredAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
coloredAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
UINavigationBar.appearance().standardAppearance = coloredAppearance
UINavigationBar.appearance().compactAppearance = coloredAppearance
UINavigationBar.appearance().scrollEdgeAppearance = coloredAppearance
UINavigationBar.appearance().tintColor = .white
}
func body(content: Content) -> some View {
ZStack{
content
VStack {
GeometryReader { geometry in
Color(self.backgroundColor ?? .clear)
.frame(height: geometry.safeAreaInsets.top)
.edgesIgnoringSafeArea(.top)
Spacer()
}
}
}
}
}
@creejohnson
Copy link

Thanks for the code. The frame doesn't resize when scrolling. Is that working for you?
Screen Shot 2020-03-11 at 12 23 36 PM

@hcancelik
Copy link

hcancelik commented May 24, 2020

Thanks for the code. The frame doesn't resize when scrolling. Is that working for you?
Screen Shot 2020-03-11 at 12 23 36 PM

@creejohnson Were you able to figure out? I'm also having the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment