[英]SwiftUI Different background colors for the top and bottom of a List
您可以將UIView
添加到標題中。 我發現 400 的高度足以覆蓋下拉而不會看到頂部邊緣。
var body: some View {
NavigationView {
List(data, id: \.self) { data in
Text("\(data)")
}
.onAppear {
let headerView = UIView(frame: CGRect(x: 0, y: -400, width: UIScreen.main.bounds.width, height: 400.0))
headerView.backgroundColor = .lightGray
UITableView.appearance().addSubview(headerView)
}
.navigationBarTitle("Title", displayMode: .inline)
}
}
如果您想要列表下方的不同背景顏色,請添加另一個UIView
以更改 backgroundView:
let backgroundView = UIView()
backgroundView.backgroundColor = .black
UITableView.appearance().backgroundView = backgroundView
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.