【发布时间】:2020-01-04 05:46:29
【问题描述】:
我想在 SwiftUI 分段选取器中设置选定的分段颜色并将文本颜色更改为白色。
我已经尝试使用选择器视图的修饰符和从外观代理修改色调颜色。不幸的是,它们似乎都不起作用。
import SwiftUI
struct PickerView: View {
@State var pickerSelection = 0
init() {
UISegmentedControl.appearance().tintColor = UIColor.blue
}
var body: some View {
Picker(selection: $pickerSelection, label: Text("")) {
Text("Active").tag(0).foregroundColor(Color.white)
Text("Completed").tag(1)
}.pickerStyle(SegmentedPickerStyle()).foregroundColor(Color.orange)
}
}
在 SwiftUI 中有什么方法可以做到这一点,还是我应该通过 UIViewControllerRepresentable 来使用 UISegmentedControl?
【问题讨论】:
-
如果我们想在同一个视图中为另一个分段选择器设置不同的色调颜色应该怎么做?