I have created a UIToolBar
programmatically and added a UITextField
on it. Now, I need that toolbar to be above the keyboard when I click in anothe
Swift 5.0 and above
let toolBar = UIToolbar(frame: CGRect(x: 0.0,
y: 0.0,
width: UIScreen.main.bounds.size.width,
height: 44.0))//1
let flexibleSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)//2
let DoneButton = UIBarButtonItem(title: "Done", style: .plain, target: target, action: #selector(tapDone))//3
toolBar.setItems([flexibleSpace, DoneButton], animated: false)
textField.inputAccessoryView = toolBar
// Done Action
@objc func tapDone() {
self.view.endEditing(true)
}