I compiled my app with Xcode 13 and iOS 15, and I noticed the UIDatePicker
is getting right aligned.
You can see that my storyboard is properly setup with constraints:
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?
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
The old behavior of the compact Date Picker (UIDatePicker) was aligned to left (with Xcode 12 + iOS 14), but now with Xcode 13 is aligned to right.
I ran into the same problem when using Xcode 13 and found a solution here.
if #available(iOS 15.0, *) {
// make date picker align to left in Xcode 13 with iOS 15
datePicker.subviews.first?.semanticContentAttribute = .forceRightToLeft
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With