Last active
October 11, 2019 05:25
-
-
Save strzempa/634e1c24d4637695ba3a41c0171e8e4a to your computer and use it in GitHub Desktop.
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
import UIKit | |
public extension UIToolbar { | |
static func toolbarDone(text: String = "Done", target: Any?, action: Selector?) -> UIToolbar { | |
let toolbar = UIToolbar() | |
toolbar.sizeToFit() | |
let doneButton = UIBarButtonItem(title: text, style: .plain, target: target, action: action) | |
toolbar.setItems([doneButton], animated: false) | |
return toolbar | |
} | |
} | |
public extension UITextField { | |
func addToolbar(text: String = "Done") { | |
let toolbar = UIToolbar() | |
toolbar.sizeToFit() | |
let doneButton = UIBarButtonItem(title: text, style: .plain, target: self, action: #selector(resignFirstResponder)) | |
let flexibleSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: self, action: nil) | |
toolbar.setItems([flexibleSpace, doneButton], animated: false) | |
self.inputAccessoryView = toolbar | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment