Skip to content

Instantly share code, notes, and snippets.

@tpthn
Created August 29, 2012 18:33
Show Gist options
  • Save tpthn/3516777 to your computer and use it in GitHub Desktop.
Save tpthn/3516777 to your computer and use it in GitHub Desktop.
iOS - dismiss keyboard when touch on background
//--Touch to dismiss keyboard
UIButton *dismissKeyboardButtonBg = [UIButton buttonWithType:UIButtonTypeCustom];
dismissKeyboardButtonBg.backgroundColor = [UIColor clearColor];
[dismissKeyboardButtonBg addTarget:self action:@selector(dismissKeyboard:) forControlEvents:UIControlEventTouchUpInside];
[dismissKeyboardButtonBg setFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[dismissKeyboardButtonBg setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[self.view addSubview:dismissKeyboardButtonBg];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment