Reputation: 9123
I have a ZStack
which has Color.orange
set on it:
struct HomeView: View {
init() {
UITabBar.appearance().barTintColor = UIColor.orange
}
var body: some View {
ZStack {
Color.orange
TabView {
Settings()
.tabItem {
Image(systemName: "gear")
Text("Settings")
}
MapKitView()
.tabItem {
Image(systemName: "location.circle.fill")
Text("Home")
}
ProfileView()
.tabItem {
Image(systemName: "person")
Text("Profile")
}
}
.font(.headline)
}
}
}
and in this ZStack
I have a TabView
with child views that all have orange ZStacks
. However these child views, including Settings()
and MapKitView()
shown below, do not have an orange status bar.
Settings()
struct Settings: View {
var body: some View {
ZStack {
Color.orange
VStack {
NavigationView {
...
}
}
}
}
}
MapKitView()
struct MapKitView: UIViewRepresentable {
func makeUIView(context: Context) -> MKMapView {
let mapView = MKMapView()
return mapView
}
func updateUIView(_ uiView: MKMapView, context: UIViewRepresentableContext<MapKitView>) {
}
}
How can I make the status bar orange across all my views?
Upvotes: 7
Views: 9101
Reputation: 2940
ZStack {
...
}
.edgesIgnoringSafeArea(.vertical) // or .top
.edgesIgnoreSafeArea
is deprecated in iOS 14 and replaced with .ignoresSafeArea
ZStack {
...
}
.ignoresSafeArea(.all, edges: [.bottom, .top])
Upvotes: 10
Reputation: 5227
If, for example, you wanted to draw a nice blur under the status bar.
YourView()
.overlay(alignment: .top) {
Color.clear // Or any view or color
.background(.regularMaterial) // I put clear here because I prefer to put a blur in this case. This modifier and the material it contains are optional.
.ignoresSafeArea(edges: .top)
.frame(height: 0) // This will constrain the overlay to only go above the top safe area and not under.
}
Upvotes: 20