how to hide the keyboard when empty area is touched on iphone

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

Custom iPhone Keyboard

Here’s an idea: modify the existing keyboard to your own needs. First, register to be notified when it appears on screen: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(modifyKeyboard:) name:UIKeyboardWillShowNotification object:nil]; Then, in your modifyKeyboard method: – (void)modifyKeyboard:(NSNotification *)notification { UIView *firstResponder = [[[UIApplication sharedApplication] keyWindow] performSelector:@selector(firstResponder)]; for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) for (UIView *keyboard in [keyboardWindow … Read more

Disable UITextField keyboard?

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

How to dismiss keyboard for UITextView with return key?

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