ios - 为什么 List 会改变 SwiftUI 中的背景颜色?
问题描述
到目前为止,基本上我所拥有的是 TabView 内的 NavigationViews。我目前正在处理的问题如下:我通过初始化程序将颜色应用于 TabView 和 NavigationView。现在,当我将任何视图(例如 Text())添加到 HomeView 时,一切都很好,但现在我想添加一个列表,它会以某种方式自动将背景颜色和所有内容更改为系统默认颜色(暗/亮)。我有将 listRowBackground 更改为特定颜色的想法,但是当将 List 向下拖动一点时,您会再次看到它后面的默认系统背景...
选项卡视图:
struct MainView: View {
init() {
UITabBar.appearance().barTintColor = Theme.current.background
UITabBar.appearance().unselectedItemTintColor = Theme.current.backgroundSecondary
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().tintColor = Theme.current.backgroundPrimary
}
var body: some View {
TabView {
HomeNavigationView().tabItem {
Image("HomeIcon")
}.tag(0)
//Left out the other tabs
...
}.edgesIgnoringSafeArea(.top)
.accentColor(Color(Theme.current.brand))
}
}
主页导航查看:
struct HomeNavigationView: View {
var body: some View {
NavigationView {
HomeView()
}
}
}
HomeView 添加简单 Text() 时:
struct HomeView: View {
var body: some View {
ZStack {
Color.red.edgesIgnoringSafeArea(.all)
Text("Test Text")
}
//Left out the NavigationBar icons
...
}
}
添加列表时的 HomeView:
struct HomeView: View {
var body: some View {
ZStack {
Color.red.edgesIgnoringSafeArea(.all)
List {
Text("first row")
Text("second row")
Text("third row")
}
}
//Left out the NavigationBar icons
...
}
}
解决方案
推荐阅读
- w2ui - 带有远程 DS 的表单中的 W2ui 组合字段
- reactjs - Axios API 调用速度不及 Postman 的
- php - 如何使用 jQuery Ajax 从 PHP 脚本中获取 JSON 数据
- python - Docx 模块未安装
- php - 有没有办法检查 .msg 文件是否在 PHP 中有附件
- php - 我想将我的 Angular(UI) PHP(backend) 应用程序部署到特定域
- python - 按年份获取所有文档 mongoDB
- flutter - Flutter,如何在 sqflite 数据库中即时搜索?
- geany - (Geany)如何在评论和字符串中自动完成工作?以及文件“geany.conf”中有关自动完成的一些信息
- react-native - 登录 react-native 应用程序时如何隐藏谷歌重新验证码?