Sha*_*man 1 list ios swift swiftui
我的 iPad 应用程序使用 SwiftUI 的 3 列布局NavigationView,2 Lists,然后是内容视图。第一个List充当主导航屏幕,(相关)代码大致如下所示:
var body: some View {
List {
...snip...
}
}
.listStyle(SidebarListStyle())
.accentColor(.white)
.introspectTableView { tableView in
tableView.backgroundColor = UIColor(Color.blue)
}
.navigationBarItems(trailing: Button(action: { self.isCreating = true }) {
Label("", systemImage: "plus")
.foregroundColor(.white)
})
}
Run Code Online (Sandbox Code Playgroud)
如代码所示,我使用了很棒的Introspect库来访问底层UITableView,以便我可以设置背景颜色。在 iOS 14 中,它可以正确呈现为蓝色背景的列表。(见下面的截图)
但是,在 iOS 15 中,不应用背景颜色。(见截图)
我尝试了几种不同的方法来在 iOS 15 中设置背景颜色。Introspect 代码似乎根本没有被调用,所以我尝试了:
List {
}
.background(Color.blue)
Run Code Online (Sandbox Code Playgroud)
那绝对没有任何作用。我也尝试设置UITableView.appearance().backgroundColor为适当的值,但这会改变UITableView全局所有 s 的背景。那不是我想要的行为。我只希望这个List有那种背景颜色。
这是 iOS 15 或 SwiftUI 中的错误吗?有没有新的方法来设置列表的背景颜色?listStyle这与 my 的设置有关吗SidebarListStyle?
任何帮助或指导将不胜感激!
我设法更改列表的背景:
List {
Section("Section") {
/// ...
}
.listRowBackground(Color.clear)
}
.listStyle(.plain)
.background(.blue)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4564 次 |
| 最近记录: |