【问题标题】:SwiftUI: Gradient background on ListSwiftUI:列表上的渐变背景
【发布时间】:2019-10-27 18:41:47
【问题描述】:

谁能告诉我如何在 SwiftUI List 上添加渐变背景?

当前代码:

struct TestView: View {
    var body: some View {
        LinearGradient(gradient: Gradient(colors: [Color.red, Color.purple]), startPoint: .top, endPoint: .bottom)
            .edgesIgnoringSafeArea(.vertical)
            .overlay(
                List {
                    Group {
                        Text("Hallo")
                        Text("World")
                    }
                    .background(Color.blue)
                }
                .background(Color.green)
                .padding(50)
        )
    }
}

当前布局,在单元格后面可以看到渐变。我想让单元格透明以查看下面的渐变。

谢谢!

【问题讨论】:

    标签: ios swift swiftui


    【解决方案1】:

    您已经添加了渐变。只需使背景颜色清晰并摆脱那些测试代码;)

    struct TestView: View {
    
        init() {
            UITableView.appearance().backgroundColor = .clear
            UITableViewCell.appearance().backgroundColor = .clear
        }
    
        var body: some View {
            LinearGradient(gradient: Gradient(colors: [Color.red, Color.purple]), startPoint: .top, endPoint: .bottom)
                .edgesIgnoringSafeArea(.vertical)
                .overlay(
                    List {
                        Group {
                            Text("Hallo")
                            Text("World")
                        }
                    }
                    .padding(50)
            )
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-19
      • 1970-01-01
      • 2021-10-24
      • 2022-08-07
      • 1970-01-01
      • 2021-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多