21.7 C
Canberra
Tuesday, October 21, 2025

SwiftUI Datepicker inside .popover doesn’t render with right dimension


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?

SwiftUI Datepicker inside .popover doesn’t render with right dimension

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)
        }
    }
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles