Can't find Done Key in numberpad or decimalpad, how can I remove the keyboard after typing number?
Can't find Done Key in numberpad or decimalpad, how can I remove the keyboard after typing number?
At least 3 ways :
- use a tap gesture in the whole view, to dismiss keyboard
h ttp://code-and-coffee.blogspot.com/2013/01/how-to-dissmis-decimal-pad-keyboard.html
- make the view a control (subclass of UIView) and add an IBAction when click on it
- add a done key to the keyboard.
h ttps://iosdevcenters.blogspot.com/2016/01/how-to-adding-return-key-in-number.html
But the proper positionning of the return key is tricky, in particular when you rotate the screen.
1. I am trying the first one, but touchesBegan never got fired.
My control did exist under a few layer of UIView and SubViews, and
I set the background to default, it still didn't work.
what I did is
a. inside viewDidLoad, set xxxTextField.delegate = self.
b. override function touchesBagan, and inside add self.view.endEditing(true)
3. I am also concerning about the layout when rotating the screen.
Effectively, connecting Editing did end to an IBAction (no need of touchBegan)
@IBAction func doneEditing(_ sender: UITextField) {
sender.resignFirstResponder()
}
is a simple solution.
You should also connect Did End On Exit
For the rotation, there is a bug when using Safe Area ; I've reported it, 3 months ago (#38117524). Closed as Duplicate.
How can we add "Return" button be added to the keyboard in modern SwiftUI and XCode 13.x The samples show outdated methods which no longer apply.
I've got a TextField and no other buttons. I need the numberPad to fire "Enter" (same as hitting return on Mac keyboard)