swiftui-list - 如何在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
. 将此init
块添加到您的View
. 这会将所有内容更改为绿色。
init() {
UITableViewCell.appearance().backgroundColor = .green
UITableView.appearance().backgroundColor = .green
}
推荐阅读
- reactjs - 如果索引页面,则从路径中删除 #/
- python - 使用 Map 和 Filter 函数查找地址 - Python
- python - 如何更改 django admin 更改列表页面选项卡的标题
- javascript - 如果 Map 中的条件 // React JS
- swift - swift combine sink receiveValue 内存泄漏
- css - 将 CSS 与 SVG 结合使用
- c# - 将输入字段中的一个值分配给 Razor 中的两个模型对象
- python - 从 python 脚本调用 ExifTool 在 Mac 中挂起,但在 Windows 中有效
- javascript - 画布javascript drawImage方法
- javascript - PM2 错误 - 错误:错误:spawn wmic ENONET