import UIKit class ViewController: UIViewController { @IBOutlet weak var dateLabel: UILabel! // Function to display the date picker dialog @IBAction func showDatePicker(_ sender: UIButton) { // Create a date picker let datePicker = UIDatePicker() datePicker.datePickerMode = .date // Create an alert controller with a date picker let alertController = UIAlertController(title: "Select a Date", message: nil, preferredStyle: .alert) alertController.view.addSubview(datePicker) // Add a "Done" button to the alert controller let doneAction = UIAlertAction(title: "Done", style: .default) { (action) in let selectedDate = datePicker.date let dateFormatter = DateFormatter() dateFormatter.dateFormat = "MMM dd, yyyy" // Customize the date format as needed let formattedDate = dateFormatter.string(from: selectedDate) self.dateLabel.text = formattedDate } alertController.addAction(doneAction) // Add a "Cancel" button to the alert controller let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) alertController.addAction(cancelAction) // Present the alert controller self.present(alertController, animated: true, completion: nil) } override func viewDidLoad() { super.viewDidLoad() } }