ios - SwiftUI 中表单部分的背景清晰?
问题描述
我正在尝试删除某些部分的白色背景,以便元素正好位于灰色背景上,但我无法删除部分背景或使其透明。
这就是我正在尝试的:
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)
到Section
and VStack
,但没有任何效果。如何在 SwiftUI 中实现这一点?
解决方案
即使在 SwiftUI 2Form
中也是建立在 UIKit 之上的,特别是UITableView
.
您需要删除 defaultUITableViewCell
的背景(仅一次,最好在 App 中init
):
UITableViewCell.appearance().backgroundColor = UIColor.clear
并使用以下方法更改背景:
Section {
VStack {
Button("Button 1") {}
Spacer()
Button("Button 2") {}
}
}
.listRowBackground(Color.clear)
推荐阅读
- google-apps-script - 在 Google 表格中执行 DELETE 操作(仅清除内容)后返回范围(实际)尺寸
- selenium-webdriver - 如何在 Selenium Python 中使用拖放列表?
- mysql - 如何使用 VBScript 从服务器管理工作室中的特定数据库执行存储过程?
- android - 持续聆听奥利奥播放的音乐
- django - Django - 无论如何要从模板上的按钮调用视图函数?
- c# - 隐藏生命条直到敌人在附近 C#
- javascript - React Native/Expo 问题将应用 URL 发送到电话或电子邮件。错误:无法获取本地颁发者证书
- php - 从外部服务器生成网站内容?
- ios - 在 Swift 中使用单例和解析 JSON
- sql-server - SSMS 保持连接打开是否有更深层次的原因?