首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否清除SwiftUI中表单节的背景?

是否清除SwiftUI中表单节的背景?
EN

Stack Overflow用户
提问于 2020-09-18 04:48:22
回答 1查看 1.2K关注 0票数 3

我正在尝试删除一些部分的白色背景,以便元素正好位于灰色背景上,但我无法删除或透明部分的背景。

这就是我正在尝试的:

代码语言:javascript
复制
struct ContentView: View {
    
    var body: some View {
        Form {
            Section {
                Text("Hello!")
                Button {
                    print("Clicked")
                } label: {
                    Text("Click Me!!")
                }
            }
            Section {
                VStack {
                    Button("Button 1") {}
                    Spacer()
                    Button("Button 2") {}
                }
            }
            .background(Color.clear) // Not doing anything
            Section {
                VStack(alignment: .leading) {
                    Text("Location")
                        .font(.headline)
                    Group {
                        Text("Abc")
                        Text("Abc")
                        Text("Abc")
                    }
                    .font(.caption)
                }
            }
        }
    }
}

它看起来是这样的:

我尝试将.background(Color.clear)添加到SectionVStack中,但没有任何效果。如何在SwiftUI中实现这一点?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-18 05:08:46

即使在SwiftUI 2中,Form也是建立在UIKit之上的,特别是UITableView

您需要移除默认 UITableViewCell 的背景(仅一次,initApp init 中):

代码语言:javascript
复制
UITableViewCell.appearance().backgroundColor = UIColor.clear

并使用以下命令更改背景:

代码语言:javascript
复制
Section {
    VStack {
        Button("Button 1") {}
        Spacer()
        Button("Button 2") {}
    }
}
.listRowBackground(Color.clear)
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63945992

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档