SwiftUI:列表上的渐变背景 [英] SwiftUI: Gradient background on List

查看:32
本文介绍了SwiftUI:列表上的渐变背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Can someone tell me how to add a gradient background on 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)
        )
    }
}

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

Current layout, where the gradient is visible behind the cells. I want to make the cells transparent to see the gradient underneath.

谢谢!

推荐答案

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

You have already added the gradient. Just make background colors clear and get rid of those test codes ;)

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)
        )
    }

这篇关于SwiftUI:列表上的渐变背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆