-1

I have code that shows a uialertview with a long message:

alert = [[UIAlertView alloc] initWithTitle:@"looong text" message:@"text to loong" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *myTextField = [alert textFieldAtIndex:0];
myTextField.delegate = self;
[alert show];   
alert.frame = CGRectMake(
    alert.frame.origin.x,
    alert.frame.origin.y - 50,
    alert.frame.size.width, 
    300);

But I get:

this instead

Gabriel.Massana
  • 8,165
  • 6
  • 62
  • 81
Yury Lego
  • 21
  • 1
  • 5
  • The code you provided doesn't seem to line up with the screen shot. Also, please clarify the problem that you're having – Aaron Feb 06 '14 at 14:55
  • wrong text of message – Yury Lego Feb 06 '14 at 15:04
  • Make the text more concise and don't set the frame explicitly. If what you want won't fit, create a custom view controller and present it... – Wain Feb 06 '14 at 15:14

2 Answers2

4

You should not mess with the UIAlertView it is even in the docs.

Subclassing Notes

The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

Better option it to create your own view and display that.

rckoenes
  • 69,092
  • 8
  • 134
  • 166
  • 1
    I cannot see that UIAlertView is subclassed here, or the view hierarchy modified. What am I overlooking? – Martin R Feb 06 '14 at 15:00
  • You care changing the size and that will also not work. You can not change anything of design/presentation of the UIAlertView. – rckoenes Feb 06 '14 at 15:02
0

I added this code to my class. And it work good for me

-(void)willPresentAlertView:(UIAlertView *)alertView {
    if(alertView.tag == ZIP_CODE_TAG){
    if ([[[UIDevice currentDevice] systemVersion] floatValue] <7)
    {
        NSArray *subviewArray = [alertView subviews];
        UILabel *message = (UILabel *)[subviewArray objectAtIndex:2];
        message.lineBreakMode = UILineBreakModeWordWrap;
        message.numberOfLines = 0;
        [message setFrame:CGRectMake(10, 95, 260, 100)];

        UIButton *okbutton = (UIButton *)[subviewArray objectAtIndex:3];
        [okbutton setFrame:CGRectMake(10, 240, 260, 42)];

        UIButton *cancelbutton = (UIButton *)[subviewArray objectAtIndex:4];
        [cancelbutton setFrame:CGRectMake(10, 287, 260, 42)];

        UITextField *textfield = (UITextField *)[subviewArray objectAtIndex:5];
        [textfield setFrame:CGRectMake(10, 198, 260, 50)];

        UITextField *placeTF = (UITextField *)[subviewArray objectAtIndex:6];
        [placeTF setFrame:CGRectMake(15, 188, 256, 50)];
    }
}

}

Yury Lego
  • 21
  • 1
  • 5