Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Put this code in your project and just set iboutlet of text field.It have some unused methods too but you can get your choice of done button using that.Then you will remove unused methods.This is just for Get Done button on number pad keyboard</p> <p>.H file</p> <pre><code>@interface aaaViewController : UIViewController { IBOutlet UITextField *txthello; UIImage *numberPadDoneImageNormal; UIImage *numberPadDoneImageHighlighted; UIButton *numberPadDoneButton; } @property (nonatomic, retain) UIImage *numberPadDoneImageNormal; @property (nonatomic, retain) UIImage *numberPadDoneImageHighlighted; @property (nonatomic, retain) UIButton *numberPadDoneButton; </code></pre> <p>.M File</p> <pre><code>- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // Add listener for keyboard display events if ([[[UIDevice currentDevice] systemVersion] floatValue] &gt;= 3.2) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil]; } else { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; } // Add listener for all text fields starting to be edited [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldDidBeginEditing:) name:UITextFieldTextDidBeginEditingNotification object:nil]; } - (void)viewWillDisappear:(BOOL)animated { if ([[[UIDevice currentDevice] systemVersion] floatValue] &gt;= 3.2) { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil]; } else { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; } [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidBeginEditingNotification object:nil]; [super viewWillDisappear:animated]; } - (UIView *)findFirstResponderUnder:(UIView *)root { if (root.isFirstResponder) return root; for (UIView *subView in root.subviews) { UIView *firstResponder = [self findFirstResponderUnder:subView]; if (firstResponder != nil) return firstResponder; } return nil; } - (UITextField *)findFirstResponderTextField { UIResponder *firstResponder = [self findFirstResponderUnder:[self.view window]]; if (![firstResponder isKindOfClass:[UITextField class]]) return nil; return (UITextField *)firstResponder; } - (void)updateKeyboardButtonFor:(UITextField *)textField { // Remove any previous button [self.numberPadDoneButton removeFromSuperview]; self.numberPadDoneButton = nil; // Does the text field use a number pad? if (textField.keyboardType != UIKeyboardTypeNumberPad) return; // If there's no keyboard yet, don't do anything if ([[[UIApplication sharedApplication] windows] count] &lt; 2) return; UIWindow *keyboardWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1]; // Create new custom button self.numberPadDoneButton = [UIButton buttonWithType:UIButtonTypeCustom]; self.numberPadDoneButton.frame = CGRectMake(0, 163, 106, 53); self.numberPadDoneButton.adjustsImageWhenHighlighted = FALSE; [self.numberPadDoneButton setTitle:@"Return" forState:UIControlStateNormal]; // [self.numberPadDoneButton setFont:[UIFont boldSystemFontOfSize:18]]; [self.numberPadDoneButton setTitleColor:[UIColor colorWithRed:77.0f/255.0f green:84.0f/255.0f blue:98.0f/255.0f alpha:1.0] forState:UIControlStateNormal]; [self.numberPadDoneButton setImage:self.numberPadDoneImageNormal forState:UIControlStateNormal]; [self.numberPadDoneButton setImage:self.numberPadDoneImageHighlighted forState:UIControlStateHighlighted]; [self.numberPadDoneButton addTarget:self action:@selector(numberPadDoneButton:) forControlEvents:UIControlEventTouchUpInside]; // Locate keyboard view and add button NSString *keyboardPrefix = [[[UIDevice currentDevice] systemVersion] floatValue] &gt;= 3.2 ? @"&lt;UIPeripheralHost" : @"&lt;UIKeyboard"; for (UIView *subView in keyboardWindow.subviews) { if ([[subView description] hasPrefix:keyboardPrefix]) { [subView addSubview:self.numberPadDoneButton]; [self.numberPadDoneButton addTarget:self action:@selector(numberPadDoneButton:) forControlEvents:UIControlEventTouchUpInside]; break; } } } - (void)textFieldDidBeginEditing:(NSNotification *)note { [self updateKeyboardButtonFor:[note object]]; } - (void)keyboardWillShow:(NSNotification *)note { [self updateKeyboardButtonFor:[self findFirstResponderTextField]]; } - (void)keyboardDidShow:(NSNotification *)note { [self updateKeyboardButtonFor:[self findFirstResponderTextField]]; } - (IBAction)numberPadDoneButton:(id)sender { UITextField *textField = [self findFirstResponderTextField]; [textField resignFirstResponder]; } - (void)dealloc { [numberPadDoneImageNormal release]; [numberPadDoneImageHighlighted release]; [numberPadDoneButton release]; [super dealloc]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload