Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)viewWillAppear:(BOOL)animtated {
- // Register the observer for the keyboardWillShow event
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardDidShowNotification object:nil];
- }
- - (void)viewWillDisappear:(BOOL)animtated {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)keyboardWillShow:(NSNotification *)notification {
- // create custom buttom
- UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
- doneButton.frame = CGRectMake(0, 163, 106, 53);
- doneButton.adjustsImageWhenHighlighted = NO;
- [doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
- [doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
- [doneButton addTarget:self action:@selector(textFieldShouldReturn:) forControlEvents:UIControlEventTouchUpInside];
- // locate keyboard view
- UIWindow *tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
- UIView *keyboard;
- for (int i = 0; i < [tempWindow.subviews count]; i++) {
- keyboard = [tempWindow.subviews objectAtIndex:i];
- // keyboard view found; add the custom button to it
- if ([[keyboard description] hasPrefix:@"<UIPeripheralHostView"] == YES) {
- [keyboard addSubview:doneButton];
- }
- }
- }
- -(BOOL)textFieldShouldReturn:(UITextField *)theTextField {
- // Set the FirstResponder of the UITextField on the layout
- [self.textField resignFirstResponder];
- return YES;
- }
Add Comment
Please, Sign In to add comment