【发布时间】:2021-12-12 01:44:40
【问题描述】:
我在 SwiftUI 中有一个时间选择器,我对选择器中文本值的任何修改都将被忽略。我该如何正确地做到这一点?我在 Big Sur 上使用 Xcode 13。
这是未经任何修改的结果:
我希望时间更大更白,所以我添加了 .font() 和 .foregroundColor() 修饰符。这是我的代码:
struct TimerPicker: View {
@Binding var customTime: CustomTime
var body: some View {
GeometryReader { geometry in
HStack (spacing: 0.0){
VStack {
Picker(selection: self.$customTime.selectedHour, label: Text("Hrs")) {
ForEach(0..<24) { hour in
Text("\(hour) hrs")
.foregroundColor(.white)
.font(.title3)
}
}
}
.frame(width: geometry.size.width * 0.33)
.clipped()
VStack {
Picker(selection: self.$customTime.selectedMin, label: Text("Min")) {
ForEach(0..<61) { min in
Text("\(min) min")
.foregroundColor(.white)
.font(.title3)
}
}
}
.frame(width: geometry.size.width * 0.33)
.clipped()
VStack {
Picker(selection: self.$customTime.selectedSecond, label: Text("Sec")) {
ForEach(0..<61) { sec in
Text("\(sec) sec")
.foregroundColor(.white)
.font(.title3)
}
}
}
.frame(width: geometry.size.width * 0.33)
.clipped()
.transition(.scale)
}
} //: Geometry
}
}
选择器值的样式没有变化。这样做的正确方法是什么?
【问题讨论】:
标签: swiftui uipickerview xcode13