swiftui - SwiftUI NavigationView 未在视图中完全扩展
问题描述
我正在使用 SwiftUI 中的 NavigationView,并且遇到了将其完全扩展到屏幕底部的问题。
我在其中创建了一个简单的列表,效果很好。但是,当我将它放在 NavigationView 中时,它会在底部创建一个灰色区域。我试过调整框架和其他一些东西都无济于事。我以前从未见过这种情况。任何帮助,将不胜感激。
struct ListingView: View {
var body: some View {
List(0..<5) { item in
Text("Test")
}
}
}
struct ListingView: View {
var body: some View {
NavigationView {
List(0..<5) { item in
Text("Test")
}
}
}
}
struct ContentView: View {
// PacificBlue Background Set Up.
init() {
UITabBar.appearance().isTranslucent = false
UITabBar.appearance().barTintColor = UIColor(Color.pacificBlue)
}
// MARK: View
var body: some View {
TabView {
SeafoodListView()
.tabItem {
Image(systemName: "line.diagonal.arrow")
Text("Market")
}.tag(0) // SeafoodMarketView
ListingView()
.tabItem {
Image(systemName: "list.bullet.rectangle")
Text("Listings")
}.tag(1) // ListingView
RequestView()
.tabItem {
Image(systemName: "megaphone")
Text("Requests")
}.tag(2) // RequestView
MessengerView()
.tabItem {
Image(systemName: "ellipsis.bubble")
Text("Messenger")
}.tag(3) // MessengerView
AccountView()
.tabItem {
Image(systemName: "person")
Text("Account")
}.tag(4) // AccountView
} // TabView
.accentColor(.white)
}
}
// MARK: Preview
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
解决方案
这是由于外观黑客...
init() {
// UITabBar.appearance().isTranslucent = false // remove this line !!!
UITabBar.appearance().barTintColor = UIColor(Color.pacificBlue)
}
替代:用配置的不透明背景替换整个外观
init() {
let newAppearance = UITabBarAppearance()
newAppearance.configureWithOpaqueBackground()
newAppearance.backgroundColor = UIColor(Color.pacificBlue)
UITabBar.appearance().standardAppearance = newAppearance
}
推荐阅读
- reactjs - 使用 google 帐户注册基于 Firebase 的 Web 应用
- python - 反转大型迭代器的有效方法
- wpf - WPF:telerik:RadGridView - 如何按用户调整高度?
- ios - 为什么http请求被意外重定向到https?
- angular - 使下拉菜单变脏
- java - 递归逻辑的调用堆栈在 java 中的行为不正确
- spacy - 如何让 SpaCy 选择由“and”或“,”分隔的名词块作为一个
- clojurescript - Cljs 重新框架未按预期显示元素
- javascript - 单击图像,尝试显示描述
- amazon-web-services - AWS CDK - 在为容器指定密钥时可以访问 Secrets Manager 密钥中的单个 (JSON) 值吗?