iOS 14.0 UIDatePicker坑

  1. 变成这个样子了


    QQ20200918-101026.png

    2.如果使用以前的样式

datepicker.preferredDatePickerStyle = .wheels
  1. 不知道是不是苹果的bug 宽高都不对
let datepicker = UIDatePicker(frame: CGRect(x: 0, y: 100, width: self.view.frame.width, height: 300))
 datepicker.preferredDatePickerStyle = .wheels  
 datepicker.backgroundColor = UIColor.yellow    
 datepicker.datePickerMode = .dateAndTime    
 self.view.addSubview(datepicker)
QQ20200918-101537.png

4.解决办法,设置frame放到datePickerMode后面设置变成正常了

let datepicker = UIDatePicker()
datepicker.preferredDatePickerStyle = .wheels
datepicker.backgroundColor = UIColor.yellow
datepicker.datePickerMode = .dateAndTime
datepicker.frame = CGRect(x: 0, y: 100, width: self.view.frame.width, height: 300)
self.view.addSubview(datepicker)
QQ20200918-101901.png

你可能感兴趣的:(iOS 14.0 UIDatePicker坑)