1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

iOS 14 UIDatePickerの以前と同じサイズ指定

Last updated at Posted at 2020-09-18

iOS14 以降でUITextField の入力補助として UIDatePicker を使っている場合に
以前と同じサイズでピッカーを利用する例


    lazy var datePicker: UIDatePicker = {
        let datePicker: UIDatePicker = UIDatePicker()
        datePicker.datePickerMode = UIDatePicker.Mode.date
        datePicker.timeZone = NSTimeZone.local
        datePicker.locale = Locale.getPreferred()
        datePicker.date = Calendar.current.date(byAdding: .hour, value: 1, to: Date())!
        datePicker.minimumDate = Date()
        
        if #available(iOS 13.4, *) {
            datePicker.frame = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: 250.0)
            datePicker.preferredDatePickerStyle = .wheels
        }
        return datePicker
    }()


    self.textField.inputView                = self.datePicker
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?