Advertisement
Guest User

How to move the buttons in a UIAlertView to make room for an inserted UITextField

a guest
Feb 27th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. UIAlertView* find = [[UIAlertView alloc] init];
  2. [find setDelegate:self];
  3. [find setTitle:@"Find"];
  4.  
  5. [find addButtonWithTitle:@"Cancel"];
  6. [find addButtonWithTitle:@"Find & Bring"];
  7. [find addButtonWithTitle:@"Find & Go"];
  8. [find addButtonWithTitle:@"Go To Next"];
  9.  
  10. [find addSubview:_findText];
  11.  
  12. CGRect frm = find.frame;
  13. int height = frm.size.height + _findText.frame.size.height + 100; // note how even 100 has no effect.
  14. [find setFrame:CGRectMake(frm.origin.x, frm.origin.y, frm.size.width, height)];
  15.  
  16. [find setNeedsLayout];
  17. [find show];
  18. [find release];
  19.  
  20. [find setMessage:@"n"];
  21.  
  22. // Create Alert
  23. UIAlertView* av = [UIAlertView new];
  24. av.title = @"Find";
  25. // Add Buttons
  26. [av addButtonWithTitle:@"Cancel"];
  27. [av addButtonWithTitle:@"Find & Bring"];
  28. [av addButtonWithTitle:@"Find & Go"];
  29. [av addButtonWithTitle:@"Go to Next"];
  30. // Make Space for Text View
  31. av.message = @"n";
  32. // Have Alert View create its view heirarchy, set its frame and begin bounce animation
  33. [av show];
  34. // Adjust the frame
  35. CGRect frame = av.frame;
  36. frame.origin.y -= 100.0f;
  37. av.frame = frame;
  38. // Add Text Field
  39. UITextField* text = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
  40. text.borderStyle = UITextBorderStyleRoundedRect;
  41. [av addSubview:text];
  42. [text becomeFirstResponder];
  43.  
  44. UIAlertView *insertScore = [UIAlertView new];
  45. [insertScore setDelegate:self];
  46. [insertScore setTitle:@"New Title!"];
  47. [insertScore addButtonWithTitle:@"Cancel"];
  48. [insertScore addButtonWithTitle:@"Ok"];
  49.  
  50. insertScore.message = @"n";
  51.  
  52. [insertScore addTextFieldWithValue:@"Input" label:@"player"];
  53.  
  54. [[insertScore textField] setDelegate:self];
  55.  
  56. [insertScore show];
  57.  
  58. [insertScore release];
  59.  
  60. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  61. {
  62. NSLog(@"%@",[[alertView textField] text]);
  63. }
  64.  
  65. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView"
  66. message:@"<Alert message>" delegate:self cancelButtonTitle:@"OK"
  67. otherButtonTitles:nil];
  68. [alert addTextFieldWithValue:@"" label:@"Text Field"];
  69.  
  70. [alert setNumberOfRows:3];
  71.  
  72. @interface UIAlertView ()
  73. - (void) addTextFieldWithValue: (NSString*) val label: (NSString*) label;
  74. - (UITextField*) textField;
  75. @end
  76.  
  77. // extend the UIAlertView class to remove the warning caused
  78. // by calling setNumberOfRows.
  79. @interface UIAlertView (extended)
  80. - (void) setNumberOfRows:(int)num;
  81. @end
  82.  
  83. [myAlert setNumberOfRows:2];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement