UIDatePicker issues in popovers on iOS 8

前端 未结 1 1633
悲&欢浪女
悲&欢浪女 2021-02-08 14:32

Is anyone else having issues with UIDatePickers in popovers on iOS 8? Suddenly our date pickers are not showing up correctly (see screenshot). It appears that part of the picker

相关标签:
1条回答
  • 2021-02-08 14:38

    I found a solution in the Apple Developer Forums (my backup knowledge base when Stack Overflow fails me).

    User Natsu had the following solution:

    I have the same problem in my project. And it causes only on iPad devices (iPhone has no problem with same code). As my understanding, UIDatePicker contains UITableView and UITableViewCell for displaying picker contents and its background color is set white as default. This is the reason of this issue. iOS 7 has UITableViewCell with white background in UIDatePicker iOS 8 has UITableView with white background in UIDatePicker So my solution is that I set these background color to nil by using UIAppearance like this:

    [[UITableView appearanceWhenContainedIn:[UIDatePicker class], nil] setBackgroundColor:nil]; // for iOS 8
    [[UITableViewCell appearanceWhenContainedIn:[UIDatePicker class], [UITableView class], nil] setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.0]]; // for iOS 7
    

    The values I set are the color used on iPhone. I'm not sure that it's a correct way to fix the issue. But at least in my environment it works well. I don't know if the problem of UIPickerView causes by same reason. But checking view hierarchy may help you.

    Since this uses UIAppearance you can put it almost anywhere. I put it in awakeFromNib in my table cell class and it worked like a charm. Thanks Natsu!

    0 讨论(0)
提交回复
热议问题