【发布时间】:2019-10-28 13:31:00
【问题描述】:
我正在尝试使用以下代码将视图背景颜色设置为黑色
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)
}
}
视图托管在一个混合的 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))
}
}
我试过.background、.listRowBackground(Color.black)和.colorMultiply(.black)我能想到的任何组合,我得到的最好的就是这个
【问题讨论】:
-
您是否尝试过更改堆栈本身的背景颜色?
标签: swiftui ios13 xcode11 swiftui-list