Skip to content

Instantly share code, notes, and snippets.

Created December 30, 2019 23:23
What would you like to do?
This adds a "done" button to your keyboard toolbar.
//Modified from:
extension UITextField {
func addKeyboardDoneButton() {
let keyboardToolBar = UIToolbar()
let flexibleSpace = UIBarButtonItem(barButtonSystemItem:
UIBarButtonItem.SystemItem.flexibleSpace, target: nil, action: nil)
let doneButton = UIBarButtonItem(barButtonSystemItem:
UIBarButtonItem.SystemItem.done, target: self, action: #selector(self.donePressed) )
keyboardToolBar.setItems([flexibleSpace, doneButton], animated: true)
self.inputAccessoryView = keyboardToolBar
@objc private func donePressed() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment