我有導航視圖的問題。當我設定它的背景顏色時,我看到下面的子視圖(紅色背景)。我也想將頂部區域用于 NavigationView。
struct ContentView: View {
init() {
UINavigationBar.appearance().backgroundColor = .black
}
var body: some View {
NavigationView {
ZStack {
Color(.red).ignoresSafeArea()
Text("Hello, world!")
.padding()
}
.navigationTitle("Main menu")
}
.edgesIgnoringSafeArea(.top)
}
}
模擬器截圖
如何讓它懸停在上面的空間?
uj5u.com熱心網友回復:
在你的視圖 init() 中試試這個:
init() {
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = .black
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/444106.html
