We need to modify NavigationView
& Form
.
NavigationView {
VStack(alignment: .leading, spacing: 0.0) {
Form {
Section {
NavigationLink(destination: EmptyView()) {
Text("-")
}
...
}
}.backgroundColor(.black) ๐
}
.navigationBarTitle("Settings", displayMode: .inline)
.navigationBarColor(.black, tintColor: .white) ๐
}
Modify NavigationView
struct NavigationBarModifier: ViewModifier {
var backgroundColor: UIColor?
init(backgroundColor: UIColor?, tintColor: UIColor?) {
self.backgroundColor = backgroundColor
let coloredAppearance = UINavigationBarAppearance()
coloredAppearance.configureWithTransparentBackground()
coloredAppearance.backgroundColor = .clear
coloredAppearance.titleTextAttributes = [.foregroundColor: tintColor as Any]
coloredAppearance.largeTitleTextAttributes = [.foregroundColor: tintColor as Any]
UINavigationBar.appearance().standardAppearance = coloredAppearance
UINavigationBar.appearance().compactAppearance = coloredAppearance
UINavigationBar.appearance().scrollEdgeAppearance = coloredAppearance
UINavigationBar.appearance().tintColor = tintColor
}
func body(content: Content) -> some View {
ZStack{
content
VStack {
GeometryReader { geometry in
Color(self.backgroundColor ?? .clear)
.frame(height: geometry.safeAreaInsets.top)
.edgesIgnoringSafeArea(.top)
Spacer()
}
}
}
}
}
extension View {
func navigationBarColor(_ backgroundColor: Color?, tintColor: Color?) -> some View {
self.modifier(NavigationBarModifier(backgroundColor: UIColor(backgroundColor ?? .white), tintColor: UIColor(tintColor ?? .black)))
}
}
Modify Form
struct FormModifier: ViewModifier {
init(backgroundColor: UIColor?) {
UITableView.appearance().backgroundColor = backgroundColor
}
func body(content: Content) -> some View {
content
}
}
extension Form {
func backgroundColor(_ backgroundColor: Color?) -> some View {
self.modifier(FormModifier(backgroundColor: UIColor(backgroundColor ?? .white)))
}
}
Top comments (0)