Luci Aghergheloaei
Luci Aghergheloaei

Reputation: 291

Date Picker looks squashed as input of a Text Field

I have a UITextField that is using UIDatePicker as an input. I set the Date Picker's style to be .inline, but the result is not what I expected

As you can see, the hour selector in the Date Picker looks squashed.

This is my code:

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let datePicker = UIDatePicker()
        datePicker.preferredDatePickerStyle = .inline
        let textField = UITextField(frame: CGRect(origin: view.center,
                                                  size: CGSize(width: 60, height: 30)))
        textField.text = "TEST"
        textField.inputView = datePicker

        self.view.addSubview(textField)
    }
}

Is this a bug? am I missing something?

Upvotes: 19

Views: 7592

Answers (1)

vysher
vysher

Reputation: 311

Try this:

if #available(iOS 13.4, *) {
   datePicker.preferredDatePickerStyle = .wheels
}

Upvotes: 21

Related Questions