hiding keyboard ios [duplicate]
If you want to hide the keyboard when you tap a button and you have more than one UITextFields in your view, then you should use: [self.view endEditing:YES]; Tap anywhere on the view, and the keyboard will disappear.
If you want to hide the keyboard when you tap a button and you have more than one UITextFields in your view, then you should use: [self.view endEditing:YES]; Tap anywhere on the view, and the keyboard will disappear.
You can do it starting from iOS 7 on a per UIResponder basis. There is textInputMode property in UIResponder class. It is readonly, but the documentation says: The text input mode identifies the language and keyboard displayed when this responder is active. For responders, the system normally displays a keyboard that is based on the … Read more
The UITextField’s inputView property is nil by default, which means the standard keyboard gets displayed. If you assign it a custom input view, or just a dummy view then the keyboard will not appear, but the blinking cursor will still appear: UIView* dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)]; myTextField.inputView = dummyView; // Hide … Read more
Updated way (recommended): – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.view endEditing:YES]; } This will end editing on all subviews and resign the first responder. Other way (enumerating over all text views): Here’s a step by step for it: Add an IBAction to your view controller, such as – (IBAction)backgroundTouch:(id)sender In the backgroundTouch action, you need … Read more
Figured I would post the snippet right here instead: Make sure you declare support for the UITextViewDelegate protocol. – (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { if([text isEqualToString:@”\n”]) { [textView resignFirstResponder]; return NO; } return YES; } Swift 4.0 update: func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { if text == … Read more