Search code examples
xcodeuidatepickerios15xcode13

UIDatePicker rendering is getting right aligned in Xcode 13 (iOS 15)


I compiled my app with Xcode 13 and iOS 15, and I noticed the UIDatePicker is getting right aligned.

enter image description here

You can see that my storyboard is properly setup with constraints:

enter image description here

This UI element was working fine, even if I download the App Store version of my app on a device running iOS 15, it renders correctly. It's only compiling it with Xcode 13 that messes is up.

Is anyone else encountering that issue?


Solution

  • Just a quick follow-up on this – I submitted this issue via Feedback Assistant and Apple told me this is expected behavior:

    Engineering has provided the following information regarding this issue:

    This is intentional and not a bug. We right-align the UIDatePicker pills for compact. Please know that if you want to change the alignment of the UIDatePicker controls on iOS 15, we now support UIControl.contentHorizontalAlignment to do just that.

    So the proper solution is as follows:

    datePicker.contentHorizontalAlignment = .left