Reader Level:
Article
iOS

Hide Keyboard on Text Field in iPhone

By Sachin Bhardwaj on Nov 23 2012
In this article I will explain the process of hiding the keyboard when we click on the keyboard's Return button or click on the background screen of the UI.
    • Like
    • Love It
    • Awesome
    • Interesting
    • It's Okay
    • Thumbs Down
  • 8.1k
  • 0

Introduction

In this article I will explain the process of hiding the keyboard when we click on the keyboard's Return button or click on the background screen of the UI.

Step 1

To hide the keyboard when we click on the Keyboard's Return button:

-(BOOL)textFieldShouldReturn:(UITextField *)textField {
   
    [textField resignFirstResponder];
 
    return YES;
}

Step 2

To hide the keyboard when we click on the background screen:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   
    [textField resignFirstResponder];

   
}

Step 3

At last we run our application and see the output:

run-in-iphone.jpg

Output

Output 1 in iPhone:

output1-in-iPhone.jpg

Output 2 in iPhone:

output2-in-iPhone.jpg

Output 3 in iPhone:

output3-in-iPhone.jpg