繁体   English   中英

如何在 SwiftUI 中将包含列表的视图的背景颜色更改回白色

[英]How to change Background Color of a View containing a List back to White in SwiftUI

我目前正在使用Lists中的SwiftUI

问题: SwiftUI 中的默认视图具有white background Color 但是,当向其中添加列表时,背景颜色会更改为systemGray6列表单元格采用white bgColor

目标:我想要一个带有white bgColor 的列表和带有systemGray6 bgcolor 的单元格

我完成了更改列表行的背景颜色:

List(users) { user in
    // ...
}
.listRowBackground(Color(UIColor.systemGray6)

但是,我找不到将屏幕的 bgColor 改white的解决方案。 我尝试了像.background(Color.white)这样明显的东西。

有没有人有这个问题的解决方案?

谢谢你的帮助。

您可以根据需要更改这些 colors,这里是一个演示示例:(使用 Xcode 12.1 / iOS 14.1 测试)

struct ContentView: View {
        
        init() {
            
            UITableView.appearance().backgroundColor = UIColor.white
        }
        
        var body: some View {
    
            
            List
            {
      
                ForEach(0 ..< 20) { index in
                    Text("Row \(index)")
                        .listRowBackground(Color(UIColor.systemGray6))
                }
    
            }
    
            
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM