关于 UIDatePicker 在iOS9 系统上的一个坑

  在使用 UIDatePicker时,在iOS9系统上上遇到一个很奇怪的问题,在其他系统版本中没发现,设置年月日格式显示的视图,在iOS9设备上出现中间月份无法显示的问题:

  关于 UIDatePicker 在iOS9 系统上的一个坑

  检查代码没问题,这个视图是使用 Xib 创建的。What Fuck!只有在iOS9上有,一直没发现这个Bug。

  后来在Stack Overflow 上找到了答案

  官方解释是

  UIPickerView and UIDatePicker are now resizable and adaptive—previously, these views would enforce a default size even if you attempted to resize them. These views also now default to a width of 320 points on all devices, instead of to the device width on iPhone. Interfaces that rely on the old enforcement of the default size will likely look wrong when compiled for iOS 9. Any problems encountered can be resolved by fully constraining or sizing picker views to the desired size instead of relying on implicit behavior.

   大致意思是说现在UIPickerView 和 UIDatePicker大小是重新可变的并且是适配的,尤其是这些视图会强制改变成默认大小即使你重新给他们定义size。在所有设备上默认宽度是 320。这个问题可以通过改变约束或调整大小来解决。

  解决方案:使用 UIDatePicker 的默认大小,去掉所有约束,问题解决。

  关于 UIDatePicker 在iOS9 系统上的一个坑