【发布时间】:2020-09-24 15:25:30
【问题描述】:
我需要创建一个包含 2 个Pickers 和 2 个DatePickers 的视图。
为了避免它们相互重叠,我使用了.clipped()。但是,这不起作用。
我可以成功调整pickers 的大小,但我无法将“选择区域”限制为它们的frame 大小。
这是我的代码:
VStack(spacing: 10) {
Picker(selection: self.$dayTypeSelectedIndex, label: Text("")) {
ForEach(0 ..< self.dayTypes.count, id: \.self) {
Text(self.dayTypes[$0])
.foregroundColor(Color.black)
}
}
.pickerStyle(SegmentedPickerStyle())
.labelsHidden()
.clipped()
Spacer()
Group {
DatePicker("", selection: self.$dateIntervalStart, displayedComponents: .hourAndMinute)
.labelsHidden()
.colorInvert()
.colorMultiply(Color.black)
.frame(maxHeight: 50)
.clipped()
Spacer()
Text("às")
.foregroundColor(Color.black)
Spacer()
DatePicker("", selection: self.$dateIntervalEnd, displayedComponents: .hourAndMinute)
.labelsHidden()
.colorInvert()
.colorMultiply(Color.black)
.frame(maxHeight: 50)
.clipped()
}
Spacer()
HStack {
Picker(selection: self.$tripNotificationDelta, label: Text("")) {
ForEach(0...60, id: \.self) {
Text($0 < 10 ? "0\($0)" : "\($0)")
.foregroundColor(Color.black)
}
}
.labelsHidden()
.frame(maxWidth: 50, maxHeight: 50)
.clipped()
Text("mins before trip")
.foregroundColor(Color.black)
}
}
}
我做错了什么?
我使用的是 XCode 12。另外,这个界面是为不运行 iOS 14 的设备构建的。
谢谢!
【问题讨论】:
标签: ios xcode datepicker swiftui picker