Enter the following code in viewDidLoad
-(void) ViewDidLoad { UITapGestureRecognizer *tapScroll = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapped)]; tapScroll.cancelsTouchesInView = NO; [scrollview addGestureRecognizer:tapScroll]; }
And define the function as follows
- (void) tapped { [self.view endEditing:YES]; }
source share