Last active
November 22, 2023 14:26
-
-
Save Winchariot/36b582625d1d2b659636dce76e27793a to your computer and use it in GitHub Desktop.
UIToolbar with a right-aligned "Done" button, for use as a keyboard accessory view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lazy var accessoryToolbarWithDoneButton: UIToolbar = { | |
let toolbar = UIToolbar(frame: CGRect.zero) | |
//only needs to be flexible in the dimension(s) you want it to be | |
//https://stackoverflow.com/questions/31822504/how-can-i-increase-the-height-of-an-inputaccessoryview | |
toolbar.autoresizingMask = [.flexibleWidth, .flexibleHeight] | |
let leftSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) | |
let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(keyboardDoneButtonTapped(_:))) | |
toolbar.items = [leftSpace, doneButton] | |
return toolbar | |
}() | |
@objc func keyboardDoneButtonTapped(_ sender: UIBarButtonItem) { | |
//resign first responder on the appropriate field | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment