如何在 swiftUI 中为列表添加背景颜色
How to add background Color to List in swiftUI
我想将背景白色更改为 SwiftUI 中列表的另一种颜色
List(listOfItems) { item in
Group {
HStack {
item.iconImage.padding()
Text(item.text).fontWeight(.regular).foregroundColor(Color("smalltext")).font(.system(size: 25))
Spacer()
Button(action: {
}) {
Image("back")
}
}.padding().background(Color("bg"))
}.listRowBackground(Color("bg"))
}.background(Color("bg"))
如果您想更改背景颜色,您可以在包含 List
的视图中执行以下操作。在您的 View
中添加此 init
块。这会将所有内容更改为绿色。
init() {
UITableViewCell.appearance().backgroundColor = .green
UITableView.appearance().backgroundColor = .green
}
我想将背景白色更改为 SwiftUI 中列表的另一种颜色
List(listOfItems) { item in
Group {
HStack {
item.iconImage.padding()
Text(item.text).fontWeight(.regular).foregroundColor(Color("smalltext")).font(.system(size: 25))
Spacer()
Button(action: {
}) {
Image("back")
}
}.padding().background(Color("bg"))
}.listRowBackground(Color("bg"))
}.background(Color("bg"))
如果您想更改背景颜色,您可以在包含 List
的视图中执行以下操作。在您的 View
中添加此 init
块。这会将所有内容更改为绿色。
init() {
UITableViewCell.appearance().backgroundColor = .green
UITableView.appearance().backgroundColor = .green
}