【问题标题】:How to set empty column background color in List in swiftUI?如何在swiftUI中的List中设置空列背景颜色?
【发布时间】:2020-01-17 19:54:50
【问题描述】:

我发现 .listRowBackground(Color.Red.Blush) 可以设置列表行列,但是在列表中有一些空行仍然是白色的。当我在列表上滚动时,它也会显示一些白色区域。有人可以帮助解决这个问题吗?还感谢您告诉我如何使用 SegmentedPickerStyle 更改颜色。该视频显示了我的问题。 https://youtu.be/aEPw5hHBkFE 谢谢!

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)

【问题讨论】:

    标签: swiftui swiftui-list


    【解决方案1】:

    我建议在您的 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)
    

    【讨论】:

      猜你喜欢
      • 2019-12-21
      • 2019-10-24
      • 2019-11-02
      • 2022-01-03
      • 1970-01-01
      • 2020-02-19
      • 2019-12-24
      • 1970-01-01
      • 2011-05-29
      相关资源
      最近更新 更多