iOS 14 UIDatePicker适配问题

iOS 14 UIDatePicker 在 13.4 新增了2个属性如下

/// 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);

原来的界面选择器样式就变成新的样式,布局也发生比较大的改变,要变成原来的样式,需添加如下代码

//_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.语言不会根据系统语言变化了,要自己设置为中文。

你可能感兴趣的:(iOS 14 UIDatePicker适配问题)