当前位置: 代码迷 >> 综合 >> iOS14 UIDatePicker 样式变化恢复
  详细解决方案

iOS14 UIDatePicker 样式变化恢复

热度:60   发布时间:2023-12-17 02:45:34.0
1.原因:

新增了一个 preferredDatePickerStyle 导致的默认UI样式变化

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

2.恢复
if (@available(iOS 14.0, *)) {
    self.datePicker.preferredDatePickerStyle = UIDatePickerStyleWheels;//此处记得再写一下frame, 在datePickerMode设置之后self.datePicker.frame = CGRectMake(0, 50, 290, 160);
}