Ale*_*tiş 1 ios13 swiftui xcode11 swiftui-list
我正在尝试使用以下代码将视图背景色设置为黑色
struct RuleList: View {[![enter image description here][1]][1]
private var presenter: ConfigurationPresenter?
@ObservedObject
private var viewModel: RowListViewModel
init(presenter: ConfigurationPresenter?, viewModel: RowListViewModel) {
self.presenter = presenter
self.viewModel = viewModel
}
var body: some View {
List(viewModel.configurations) { configuration in
RuleListRow(website: configuration.website).background(Color.black)
}.background(Color.black)
}
}
struct RuleListRow: View {
var website: Website
@State private var websiteState = 0
var body: some View {
VStack {
Text(website.id).foregroundColor(.white)
Picker(website.id, selection: $websiteState) {
Text("Permis").tag(0)
Text("Ascuns").tag(1)
Text("Blocat").tag(2)
}.pickerStyle(SegmentedPickerStyle()).background(Color.crimson)
}.listRowBackground(Color.green)
}
}
Run Code Online (Sandbox Code Playgroud)
该视图托管在混合UIKit-SwiftUI故事板中,因此此特定视图嵌入在Hosting控制器中
class ConfigurationHostingController: UIHostingController<RuleList> {
private var presenter: ConfigurationPresenter = ConfigurationPresenter()
required init?(coder: NSCoder) {
super.init(rootView: RuleList(presenter: presenter, viewModel: presenter.rowListViewModel))
}
}
Run Code Online (Sandbox Code Playgroud)
我试过的任意组合.background
,.listRowBackground(Color.black)
和.colorMultiply(.black)
我能想到的,我得到了最好的是这
所有SwiftUI List
都由UITableView
iOS中的a支持。因此,您需要更改tableView的背景颜色。但是由于Color
和UIColor
值略有不同,因此您可以摆脱UIColor
。
struct ContentView: View {
init() {
UITableView.appearance().backgroundColor = .clear // tableview background
UITableViewCell.appearance().backgroundColor = .clear // cell background
}
var body: some View {
List {
,,,
}
.background(Color.yellow)
}
}
Run Code Online (Sandbox Code Playgroud)
现在,您可以使用所需的任何背景(包括所有Color
)
请注意,顶部和底部的白色区域是安全的,您可以使用.edgesIgnoringSafeArea()
修饰符来摆脱它们。
归档时间: |
|
查看次数: |
166 次 |
最近记录: |