Hide Keyboard on Text Field in iPhone

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

Up Next
    Ebook Download
    View all
    Learn
    View all