The 'preferredDatePickerStyle' property in SwiftUI is used to control the visual style of the date picker. You can choose from three options: 'automatic', 'compact', and 'wheel'.

  • 'automatic': This style automatically adapts to the platform and available screen space. It defaults to 'wheel' on iOS 14+ and macOS 11+, while opting for 'compact' on older versions.

  • 'compact': This style presents a compact date picker, ideal for scenarios where space is limited, like within a toolbar or navigation bar.

  • 'wheel': This style features a wheel-like interface, allowing users to scroll through available date options. It's the default style on iOS 14+ and macOS 11+.

Example Usage:

DatePicker('Select Date', selection: $selectedDate)
    .preferredDatePickerStyle(.wheel)
SwiftUI DatePicker Styles: Automatic, Compact, and Wheel

原文地址: https://www.cveoy.top/t/topic/pe7K 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录