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?
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“.
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.
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.
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.
_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
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
Try this:
if #available(iOS 13.4, *) {
datePicker.preferredDatePickerStyle = .wheels
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With