Add a Done button within a pop-up datePickerView in Swift?

前端 未结 5 750
轮回少年
轮回少年 2020-12-08 16:32

I want to add a Done button within a popped up datePickerView in Swift.

Here is the code:

@IBOutlet var datePicker: UITextField!

@IBAction func date         


        
5条回答
  •  甜味超标
    2020-12-08 16:52

    In Swift 5

    If you want only Done button on DatePicker use my code

    //Write toolbar code for done button
    let toolBar = UIToolbar()
    toolBar.barStyle = .default
    toolBar.isTranslucent = true
    let space = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
    let doneButton = UIBarButtonItem(title: "Done", style: .done, target: self, action: #selector(onClickDoneButton))
    toolBar.setItems([space, doneButton], animated: false)
    toolBar.isUserInteractionEnabled = true
    toolBar.sizeToFit()
    dobTF.inputAccessoryView = toolBar //Change your TextField name here
    
    @objc func onClickDoneButton() {
        self.view.endEditing(true)
    }
    

提交回复
热议问题