如何在swiftUI中设置列表中的空列背景色?
我发现.listRowBackground(Color.Red.Blush)可以设置列表行列,但是列表中有一些空行仍然是白色的。当我在列表上滚动时,它也会显示一些白色区域。有人能帮我解决这个问题吗?还感谢您告诉我如何使用分段选择器样式更改颜色。这段视频显示了我的问题。 谢谢大家!如何在swiftUI中设置列表中的空列背景色?,swiftui,swiftui-list,Swiftui,Swiftui List,我发现.listRowBackground(Color.Red.Blush)可以设置列表行列,但是列表中有一些空行仍然是白色的。当我在列表上滚动时,它也会显示一些白色区域。有人能帮我解决这个问题吗?还感谢您告诉我如何使用分段选择器样式更改颜色。这段视频显示了我的问题。 谢谢大家! struct UserNotificationCellView: View { @ObservedObject var userNotification: UserNotification @ObservedObjec
struct UserNotificationCellView: View {
@ObservedObject var userNotification: UserNotification
@ObservedObject var userNotifications: UserNotifications
var body: some View {
{
......
}
.padding(.horizontal,20)
.cornerRadius(14)
.listRowBackground(Color.Red.Blush)
// .background(Color.Red.Blush)
}
}
下面是我的列表代码
List {
ForEach(userNotifications1.userNotificationsArray, id: \.notifyId) { (userNotification) in
UserNotificationCellView(userNotification: userNotification,userNotifications: self.userNotifications1)
// .listRowBackground(Color.Red.Blush)
}.colorMultiply(Color.Red.Blush)
Spacer()
}.environment(\.defaultMinListRowHeight, 80)
我建议在AppDelegate类中添加全局样式。从这里,您可以通过外观更改SwiftUI当前无法访问的类属性
UITableView.appearance().backgroundColor = .clear
UISegmentedControl.appearance().....
从这里,您可以更改列表背景颜色和需要更改的任何分段控件属性
对于空单元格,可以尝试添加空页脚
List {
Section(footer: self.footer) {
ForEach(userNotifications1.userNotificationsArray, id: \.notifyId) { (userNotification) in
UserNotificationCellView(userNotification: userNotification,userNotifications: self.userNotifications1)
// .listRowBackground(Color.Red.Blush)
}.colorMultiply(Color.Red.Blush)
}
}.environment(\.defaultMinListRowHeight, 80)