Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 875
Luci Aghergheloaei Avatar asked Aug 31 '20 12:08

Luci Aghergheloaei


People also ask

How do I add a date picker to a form?

In this article, we will learn how to add a datepicker in form using HTML5. Approach: Create an HTML document that contains a form with an input field. Using a type attribute in input element which is set to “datetime-local“.

How do you close a date picker?

The datepicker is tied to a standard form input field. Focus on the input (click, or use the tab key) to open an interactive calendar in a small overlay. Choose a date, click elsewhere on the page (blur the input), or hit the Esc key to close.

How to edit selected date in a textformfield using date picker?

We store the value that is returned from the date picker in a variable called picked initialDate is the selected date when the picker first opens to create a max and min values in the date picker we use firstDate and lastDate We then create a condition to edit the TextFormField text and update the selectedDate.

How do I use the desktop date picker?

Desktop date pickers allow the selection of a specific date and year. The desktop date picker displays a date input field by default, and a dropdown calendar appears when the user taps on the input field. The user can interact with either form of date entry.

What is the difference between _datecontroller and selecteddate?

_dateController is a TextEditingController that we use to manually change the text inside the date text field that we are going to create selectedDate is used to store the date that is returned from the date picker Let's import and add the NewTaskForm widget to our main.dart file in order to see our changes as we work

How do I get the selected value from the date picker?

Let's create the _selectDate() function that opens the date picker and assigns the selected value to the selectedDate variable in our class outside the build function. We use an async function because the showDatePicker is a Future. We store the value that is returned from the date picker in a variable called picked


1 Answers

Try this:

if #available(iOS 13.4, *) {
   datePicker.preferredDatePickerStyle = .wheels
}
like image 196
vysher Avatar answered Oct 07 '22 00:10

vysher