skip to Main Content

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?

2

Answers


  1. 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
        }
    
    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search