【发布时间】:2020-09-17 22:38:03
【问题描述】:
我有一个带有背景的 SwiftUI 列表。在 iOS 13 中,通过在 init() 中设置 UITableView 属性,我成功地使列表透明,以便背景显示出来。在 iOS 14 中,行为发生了变化。下面的代码 sn-p 显示了初始化设置。我已确认此提取的 sn-p 在 iOS 13 中按预期工作(通过列表显示背景),但在 iOS 14 中,列表中填充的行会阻塞背景,就好像背景是白色且不清晰一样。
还有其他人看过吗?是否有另一种方法可以使列表透明并适用于 iOS 13 和 14?
struct RecorderList: View {
init(){
UITableView.appearance().backgroundColor = .clear
UITableViewCell.appearance().backgroundColor = .clear
UINavigationBar.appearance().largeTitleTextAttributes = [
.foregroundColor: UIColor.purple,
.font: UIFont(name:"Papyrus", size: 40) ?? UIFont.systemFont(ofSize:40)]
}
var body: some View {
NavigationView {
ZStack (alignment: .top){
Image("background")
.resizable()
.scaledToFit()
List {
Text("One")
.font(.title)
.background(Color.clear)
Text("Two")
.font(.title)
.background(Color.clear)
Text("Three")
.font(.title)
.background(Color.clear)
Text("Four")
.font(.title)
.background(Color.clear)
Text("Five")
.font(.title)
.background(Color.clear)
}
}
.navigationBarTitle("Recorders")
}
}
}
【问题讨论】:
-
有同样的问题。看来,
UITableViewCell.appearance().backgroundColor = ...在 iOS 14 中没有效果——我称之为错误。模拟器 iOS 14.5 中的行为仍然相同。listRowBackground(..)也不起作用。