【问题标题】:Transparent background for List列表的透明背景
【发布时间】:2021-10-27 15:03:25
【问题描述】:

我希望我的 TableView 变得透明以便看到渐变背景。我试过 ListRowBackground 但它不起作用。我错过了什么吗? 如果除了我的背景之外,我还想在我的 Tableview 中添加另一个渐变,我应该如何进行?谢谢。

结构测试:查看 {

init() {
    UITableView.appearance().backgroundColor = UIColor.clear
    UITableViewCell.appearance().backgroundColor = .clear
    UITableView.appearance().separatorStyle = .none
}

var body: some View {
    NavigationView {
        ZStack {
            LinearGradient(gradient: Gradient(colors: [Color.red, Color.blue]), startPoint: .top, endPoint: .bottom)
                .edgesIgnoringSafeArea(.all)
                .overlay(
                    
                    List(iphonedata) { data in
                        CompleteCell(contact: data)
                }
            )
        }
        .navigationTitle("Version signées")

    }
}

}

【问题讨论】:

  • "Translucide background for List" 英文中的“Translucide”是什么意思?你的意思是“半透明”?
  • @El Tomato ,透明,不上色

标签: ios swiftui background cell gradient


【解决方案1】:

您需要明确List 。通过将listRowBackground(_:) 设置为Color.clear 来做到这一点,因此它是透明的。

List(iphonedata) { data in
    CompleteCell(contact: data)
        .listRowBackground(Color.clear)
}

注意:如果你将它应用到List,这个修饰符不起作用,它只适用于列表中的

【讨论】:

  • 除非CompleteCell 在某处应用它自己的background,否则这是可行的。工作示例:List([1, 2, 3, 4, 5], id: \.self) { data in Text(String(data)).listRowBackground(Color.clear) }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-08
  • 2011-10-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多