Guest User

Untitled

a guest
Jan 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. - (void)viewWillAppear:(BOOL)animtated {
  2.  
  3. // Register the observer for the keyboardWillShow event
  4. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardDidShowNotification object:nil];
  5.  
  6. }
  7.  
  8. - (void)viewWillDisappear:(BOOL)animtated {
  9. [[NSNotificationCenter defaultCenter] removeObserver:self];
  10. }
  11.  
  12. - (void)keyboardWillShow:(NSNotification *)notification {
  13. // create custom buttom
  14. UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
  15. doneButton.frame = CGRectMake(0, 163, 106, 53);
  16. doneButton.adjustsImageWhenHighlighted = NO;
  17. [doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
  18. [doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
  19. [doneButton addTarget:self action:@selector(textFieldShouldReturn:) forControlEvents:UIControlEventTouchUpInside];
  20.  
  21. // locate keyboard view
  22. UIWindow *tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
  23. UIView *keyboard;
  24. for (int i = 0; i < [tempWindow.subviews count]; i++) {
  25. keyboard = [tempWindow.subviews objectAtIndex:i];
  26. // keyboard view found; add the custom button to it
  27. if ([[keyboard description] hasPrefix:@"<UIPeripheralHostView"] == YES) {
  28. [keyboard addSubview:doneButton];
  29. }
  30. }
  31. }
  32.  
  33. -(BOOL)textFieldShouldReturn:(UITextField *)theTextField {
  34. // Set the FirstResponder of the UITextField on the layout
  35. [self.textField resignFirstResponder];
  36. return YES;
  37. }
Add Comment
Please, Sign In to add comment