Question: I want to takeout the keyboard when the user clicks on the background or any other item on the view.

I found out that the following code will take it off. But where should i add it.

```
[self.view endEditing:YES];

```

All my UI components are created programatically.

Answer: 
It's super simple, you only need to implement this code in your .m file:

```
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

[self.view endEditing:YES];

}

```

This will do.
Use below code

```
UITapGestureRecognizer *recognizer;
recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:nil];
recognizer.numberOfTouchesRequired=1;
[self.view addGestureRecognizer:recognizer];
 recognizer.delegate = self;

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    [userName resignFirstResponder];
    [passWord resignFirstResponder];
    return NO;
}

```