iOS 14 UIDatePicker 在 13.4 新增了2個屬性以下ios
/// Request a style for the date picker. If the style changed, then the date picker may need to be resized and will generate a layout pass to display correctly. @property (nonatomic, readwrite, assign) UIDatePickerStyle preferredDatePickerStyle API_AVAILABLE(ios(13.4)) API_UNAVAILABLE(tvos, watchos); /// The style that the date picker is using for its layout. This property always returns a concrete style (never automatic). @property (nonatomic, readonly, assign) UIDatePickerStyle datePickerStyle API_AVAILABLE(ios(13.4)) API_UNAVAILABLE(tvos, watchos);
typedef NS_ENUM(NSInteger, UIDatePickerStyle) { /// Automatically pick the best style available for the current platform & mode. UIDatePickerStyleAutomatic, /// Use the wheels (UIPickerView) style. Editing occurs inline. UIDatePickerStyleWheels, /// Use a compact style for the date picker. Editing occurs in an overlay. UIDatePickerStyleCompact, /// Use a style for the date picker that allows editing in place. UIDatePickerStyleInline API_AVAILABLE(ios(14.0)) API_UNAVAILABLE(tvos, watchos), } API_AVAILABLE(ios(13.4)) API_UNAVAILABLE(tvos, watchos);
原來的界面選擇器樣式就變成新的樣式
那怎麼才能變成原來的樣式呢?
atom
直接上代碼spa
//_datePicker.backgroundColor = [UIColor whiteColor]; 背景色是透明的。 if (@available(iOS 13.4, *)) { _datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];//新發現這裏不會根據系統的語言變了 _datePicker.preferredDatePickerStyle = UIDatePickerStyleWheels; } else { // Fallback on earlier versions }
根據項目中的界面樣式,發現了2個問題,
1.UIDatePicker 設置背景色沒有用了,是透明的。
2.語言不會根據系統語言變化了,要本身設置爲中文。
3d
修復調整後效果以下
code