Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 425
KBog Avatar asked Sep 23 '21 06:09

KBog


2 Answers

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
like image 95
jwuki Avatar answered Nov 15 '22 08:11

jwuki


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
    }
like image 42
benck Avatar answered Nov 15 '22 07:11

benck