Hiding the Status Bar in SwiftUI: How to Hide Your App's Status Bar with or Without Animation
Hide Status Bar : In SwiftUI, you can hide the status bar by using the .statusBar modifier. This can be applied to any view, such as the Text.
Please note: the Status Bar will only be visible in the simular or on your device. You won't be able to see the Status Bar in the Preview.
Hide Status Bar
Text("Status bar")
.statusBar(hidden: true)
..
Toggle Status Bar
You can toggle the Status bar by using a state.
struct ContentView: View {
@State var isHidden = false
var body: some View {
Text("Status bar")
.statusBar(hidden: isHidden)
.onTapGesture {
isHidden = true
}
}
}
..
With Animation
You can also apply a fade out animation on your status bar change using withAnimation.
withAnimation {
isHidden = true
}
..
Comments
Post a Comment