Reputation: 12847
I am using TextFieldEffects for custom UITextFields. Creating the textfield was pretty straight forward..
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let textField = HoshiTextField(frame: textFieldFrame)
textField.placeholderColor = .darkGrayColor()
textField.foregroundColor = .lightGrayColor()
view.addSubView(textField)
}
}
For dismissing the keyboard, I tried to do what I usually do, but unfortunately no luck.
func textFieldShouldReturn(textField: HoshiTextField) -> Bool {
self.view.endEditing(true)
return false
}
func dismissKeyboard() {
view.endEditing(true)
}
Do you have any suggestions?
Upvotes: 0
Views: 733
Reputation: 5186
Confirm the UITextFieldDelegate protocol to your ViewController and assign textField.delegate = self
and then implement the following delegate method:
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.view.endEditing(true)
}
For better understanding please see my code snipet
Upvotes: 2
Reputation: 10317
class ViewController: UIViewController, UITextFieldDelegate //add this protocol
{
...
func ... {
let textField = HoshiTextField(frame: textFieldFrame)
textField.placeholderColor = .darkGrayColor()
textField.foregroundColor = .lightGrayColor()
textField.delegate = self
}
}
Upvotes: 1