I want to use a SwiftUI DatePicker
inside a .popover
(each iPhone and iPad, iOS 16+). Whereas this works wonderful usually, the DatePicker
isn’t sized accurately when the .popover
seems. Its measurement exceeds the .popover
body and the picker isn’t completly seen. When selecting a knowledge, the picker resizes accurately.
Xcode console reveals:
UIDatePicker 0x16d30dff0 is being laid out beneath its minimal width of 280. This will likely not appear to be anticipated, particularly with bigger than regular font sizes.
UIDatePicker 0x16d30dff0 is being laid out beneath its minimal width of 280. This will likely not appear to be anticipated, particularly with bigger than regular font sizes.
UICalendarView's top is smaller than it could possibly render its content material in; defaulting to the minimal top.
UICalendarView's top is smaller than it could possibly render its content material in; defaulting to the minimal top.
UIDatePicker 0x16d30dff0 is being laid out beneath its minimal width of 280. This will likely not appear to be anticipated, particularly with bigger than regular font sizes.
Because the DatePicker
resizes itself accurately when selecting a date, the scale appears to be sufficent. Find out how to resize the DatePicker
correctly on look?
struct DatePickerView: View {
@State non-public var showPopover: Bool = false
@State non-public var date: Date = Date()
var physique: some View {
Button("Present Date Popover") {
showPopover.toggle()
}
.buttonStyle(.borderedProminent)
.popover(isPresented: $showPopover) {
DatePicker("", choice: $date, displayedComponents: [.date])
.datePickerStyle(.graphical)
.padding([.leading, .trailing])
// explicitly setting the scale doesn't remedy the issue
.body(width: 300, top: 300)
.presentationCompactAdaptation(.popover)
}
}
}