非常简单,只需要statusBar() modifier
Text("No status bar, please")
.statusBar(hidden: true)
注意:This modifier is available only on iOS.
通过变量控制statusBar示例
struct ContentView: View {
@State private var hideStatusBar = false
var body: some View {
Button("Toggle Status Bar") {
withAnimation {
hideStatusBar.toggle()
}
}
.statusBar(hidden: hideStatusBar)
}
}
原文:https://www.hackingwithswift.com/quick-start/swiftui/how-to-hide-and-show-the-status-bar