iOS 7 UIDatePicker height inconsistency?

拟墨画扇 提交于 2019-11-28 17:26:47

I can confirm that using UI(Date)Picker in storyboards has a different height (162.0) than in "reality" (216.0). Therefore you have to adjust the space to container view to fit that "real" date picker height or try to solve it using auto-layout.

Here is a funny trick I just found: put the UIDatePicker inside a dedicated view with a constraint of 162 points in height (add 0 point vertical constraints from top and bottom of the picker to this new superview). This seems to have the effect of forcing the picker to keep the size of 162 points.

You can add the option of clipping the subviews to be sure that the UIDatePicker will not escape from its new prison.

EDIT: after some more tests, it seems that by just adding a height constraint of 162 points to the UIDatePicker, it will keep its "IB size". And, to answer @Andrew's comment, here is what it will look like:

You can change the width and height by simply giving it width and height constraints. Without doing that, the UIDatePicker just acts weird, I've found.

Setting clipsToBounds property to YES on my UIDatePicker object helped me.

datePicker.clipsToBounds = YES;

For XIB's you can directly tick the checkbox for Clip Subviews :

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!