I want to use a SwiftUI DatePicker
inside a .popover
(each iPhone and iPad, iOS 16+). Whereas this works positive normally, the DatePicker
isn’t sized accurately when the .popover
seems. Its dimension exceeds the .popover
body and the picker isn’t completly seen. When choosing an information, the picker resizes accurately.
Xcode console reveals:
UIDatePicker 0x16d30dff0 is being laid out beneath its minimal width of 280. This will likely not seem like anticipated, particularly with bigger than regular font sizes.
UIDatePicker 0x16d30dff0 is being laid out beneath its minimal width of 280. This will likely not seem like anticipated, particularly with bigger than regular font sizes.
UICalendarView's peak is smaller than it may well render its content material in; defaulting to the minimal peak.
UICalendarView's peak is smaller than it may well render its content material in; defaulting to the minimal peak.
UIDatePicker 0x16d30dff0 is being laid out beneath its minimal width of 280. This will likely not seem like anticipated, particularly with bigger than regular font sizes.
Because the DatePicker
resizes itself accurately when choosing a date, the dimensions appears to be sufficent. Tips on 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 dimensions doesn't clear up the issue
.body(width: 300, peak: 300)
.presentationCompactAdaptation(.popover)
}
}
}