Swift UI将列表覆盖为背景色 [英] Swift UI Overlay a list to a background color

查看:327
本文介绍了Swift UI将列表覆盖为背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想将颜色"设置为我的列表的背景色.找不到任何有效的方法,

I just want to set a Color as background color to my list. Can't find anything that work,

看来不可能,我不想更改行中的每种颜色.

It looks like is not possible, I don't want to change every single color of my row.

任何提示怎么做?看起来SwiftUIList不允许背景颜色,它只允许每个原始颜色.

Any tips how to do it? Looks like SwiftUI and List don't allow the background color, it allow only color per single raw.

struct ContentView: View {
    var body: some View {
        ZStack {
            RadialGradient(gradient: Gradient(colors: [.orange, .red]), center: .center, startRadius: 100, endRadius: 470).edgesIgnoringSafeArea(.all)
                .overlay(
                    List(0 ..< 5) { item in
                        Text("Test")
                    }
            )
        }
    }
}

推荐答案

您可以添加

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

到您的结构,然后为您的列表设置背景.

to your struct and then set background for your list.

这篇关于Swift UI将列表覆盖为背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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