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

修复调整后效果如下
在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值