iOS 14.0 UIDatePicker坑

作者: iOS虞 | 来源:发表于2020-09-18 10:19 被阅读0次
    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坑

        本文链接:https://www.haomeiwen.com/subject/xnidyktx.html