UITextField in UIAlertView


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. - (void) doAlertWithTextField {
  2. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Congratulations!" message:@"You earned a top score! Enter your name:nn"
  3. delegate:self
  4. cancelButtonTitle:nil
  5. otherButtonTitles:@"OK", nil];
  6. alert.tag = kTag_EnterNameAlert;
  7.  
  8. CGRect entryFieldRect = CGRectZero;
  9. if( UIDeviceOrientationIsPortrait( [UIApplication sharedApplication].statusBarOrientation ) ) {
  10. entryFieldRect = CGRectMake(12, 90, 260, 25);
  11. }
  12. else {
  13. entryFieldRect = CGRectMake(12, 72, 260, 25);
  14. }
  15.  
  16. UITextField *nameEntryField = [[UITextField alloc] initWithFrame:entryFieldRect];
  17. nameEntryField.tag = kTag_NameEmtryField;
  18. nameEntryField.backgroundColor = [UIColor whiteColor];
  19. nameEntryField.keyboardType = UIKeyboardTypeAlphabet;
  20. nameEntryField.keyboardAppearance = UIKeyboardAppearanceAlert;
  21. nameEntryField.autocorrectionType = UITextAutocorrectionTypeNo;
  22. nameEntryField.clearButtonMode = UITextFieldViewModeWhileEditing;
  23. [alert addSubview:nameEntryField];
  24. [nameEntryField becomeFirstResponder];
  25. [nameEntryField release];
  26.  
  27. [alert show];
  28. [alert release];
  29. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.