Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set time picker at top of inline style Date picker in iOS 14?

I have set inline style date for iOS 14. In this date picker timer picker is display at bottom. I want to display that time picker at top of inline style date picker like display in iOS default calendar app.

My app screen shot: enter image description here

iOS default calendar app screen shot: enter image description here

like image 438
Yogendra Patel Avatar asked Oct 26 '20 10:10

Yogendra Patel


People also ask

How do I install date picker time?

Display the current date in a date pickerClick the Data tab. Under Default Value, click Insert Formula . In the Insert Formula dialog box, click Insert Function. In the Categories list in the Insert Function dialog box, click Date and Time.

What is date picker and time picker?

A date picker, popup calendar, date and time picker, or time picker is a graphical user interface widget which allows the user to select a date from a calendar and/or time from a time range.

What are the various ways of using DatePicker?

In android DatePicker having two modes, the first one shows the complete calendar and the second one shows the dates in the spinner view. One can create a DatePicker control in two ways either manually in the XML file or create it in the Activity file programmatically.


1 Answers

UIKit does not officially support Time Picker above the Date Picker inside an in-line UIDatePicker.

However, you can just create 2 Date Pickers, one for the date and one for the time, and then arrange them however you want.

This code that I made might help you:

let time = timePicker.date
var date = datePicker.date
date = Calendar.current.startOfDay(for: date)

let calendar = Calendar.current

var timeInterval: TimeInterval = 0
timeInterval += Double(calendar.component(.second, from: time))
timeInterval += Double(calendar.component(.minute, from: time)) * 60
timeInterval += Double(calendar.component(.hour, from: time)) * 3600

date.addTimeInterval(timeInterval)

Then use the variable date , and everything should work like in a regular date-and-time Date Picker.

like image 155
אורי orihpt Avatar answered Oct 04 '22 21:10

אורי orihpt