简体   繁体   English

SwiftUI:如何使列表视图透明? 如何更改列表视图背景颜色?

[英]SwiftUI: how to make List view transparent? How to change List view background color?

in case of create the List with Swift UI I have uncontrollable background of the List如果使用 Swift UI 创建列表,我的列表背景将无法控制

在此处输入图像描述

Looks like there is absent "native" way to change background color of List background color.看起来没有“本机”方式来更改列表背景颜色的背景颜色。

How to make it transparent?如何让它透明?

(Answer is below) (答案如下)

SO, If you want to have transparent list: you need to:所以,如果你想有透明的列表:你需要:

  1. This is must be Mac Catalyst project (for access to UIKit from the project)这必须是 Mac Catalyst 项目(用于从项目中访问 UIKit)

This must be enough;这一定足够了;

swiftUI透明列表


if you need to change background color of list如果您需要更改列表的背景颜色

  1. This is must be Mac Catalyst project (for access to UIKit from the project)这必须是 Mac Catalyst 项目(用于从项目中访问 UIKit)

This is needed to have access to UI* classes这是访问 UI* 类所必需的

  1. You must to add init that is required for such changes您必须添加此类更改所需的 init

     import SwiftUI struct ContentView: View { //Solution is this method. init(){ UITableView.appearance().backgroundColor =.red UITableViewCell.appearance().backgroundColor =.red UITableView.appearance():tableFooterView = UIView() } var body. some View { List() { Text("bla") Text("Bla") }.padding(,all, 200) } }

result:结果:

在此处输入图像描述


Also there is possible to use another way to post some lists... Like:也可以使用另一种方式发布一些列表......比如:

Really close to List element set but with horizontal listing (you can modify it to vertical variation ):非常接近 List 元素集但具有水平列表(您可以将其修改为垂直变化):

       ScrollView(showsIndicators: false) {
            VStack{
                ForEach (filteredStatus) { status in
                    HStack{
                        Text(status)
                        Spacer()
                    }
                    
                    .background(Color.red)
                }
            }
        }

But preferred is to use another solutions但首选是使用另一种解决方案

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

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