![](/img/trans.png)
[英]How to change background color of the NavigationView in SwiftUI?
[英]How can I change the background color in SwiftUI when I am using NavigationView and List?
我想更改背景顏色,但我使用的是 NavigationView 和 List。 這就是為什么 ZStack 方法對我不起作用的原因。
這是我的代碼:
NavigationView {
List {
Text("Some Text")
}
.navigationBarTitle("Test")
}
您可以在列表中使用 .listRowBackground。
ZStack{
Color.blue
NavigationView {
ZStack{
Color.red
List {
ZStack{
Color.green
Text("Some Text").background(Color.green).opacity(0.5)
}.listRowBackground(Color.red)
}
}
.navigationBarTitle("Test")
}.padding()
}
NavigationView {
List {
Text("Some Text")
}
.navigationBarTitle("Test")
}.colorMultiply(Color.green)
最后我找到了我的問題的答案:
init() {
UITableView.appearance().backgroundColor = UIColor(named: "CustomBackgroundColor")
UITableViewCell.appearance().backgroundColor = UIColor(named: "CustomBackgroundColor")
UITableView.appearance().tableFooterView = UIView()
}
var body: some View {
NavigationView {
List {
Text("Hello")
}
.navigationBarTitle("Test")
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.