Set done bar in numberpad of UITextfield in swift


extension UITextField
{
    open override func awakeFromNib() {
        super.awakeFromNib()
        if self.keyboardType == UIKeyboardType.numberPad {
            let toolbar = UIToolbar.init()
            toolbar.sizeToFit()
            let barBtnDone = UIBarButtonItem.init(barButtonSystemItem: UIBarButtonSystemItem.done, target: self, action: #selector(btnBarDoneAction))
            toolbar.items = [barBtnDone]
            self.inputAccessoryView = toolbar
        }
    }

    @objc func btnBarDoneAction() { self.resignFirstResponder() }
 }