Skip to content

Instantly share code, notes, and snippets.

@lawreyios
Created May 13, 2020 10:12
Show Gist options
  • Save lawreyios/0883f7ed39e3723cf3275b6b66d48114 to your computer and use it in GitHub Desktop.
Save lawreyios/0883f7ed39e3723cf3275b6b66d48114 to your computer and use it in GitHub Desktop.
extension View {
func navigationBarColor(_ backgroundColor: UIColor?, textColor: UIColor?) -> some View {
modifier(NavigationBarModifier(backgroundColor: backgroundColor, textColor: textColor))
}
}
struct NavigationBarModifier: ViewModifier {
var backgroundColor: UIColor?
var textColor: UIColor?
init( backgroundColor: UIColor?, textColor: UIColor?) {
self.backgroundColor = backgroundColor
UINavigationBar.appearance().largeTitleTextAttributes = [.foregroundColor: textColor ?? .black]
UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: textColor ?? .black]
}
func body(content: Content) -> some View {
ZStack{
content
VStack {
GeometryReader { geometry in
Color(self.backgroundColor ?? .clear)
.frame(height: geometry.safeAreaInsets.top)
.edgesIgnoringSafeArea(.top)
Spacer()
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment