Search code examples
iphoneobjective-cios4uialertview

How to generate multi-line rather than single line with UIAlertView?


This is my code

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Added to Cart" message:@"Some items are added for time being!" delegate:self cancelButtonTitle:@"View Cart" otherButtonTitles:@"Continue \n Shopping", nil];
alert.tag = 20;
[alert show];

I get output like this:
enter image description here

I need like this:
enter image description here


Solution

  • I have manual solution for you. But I think its not a good solution:

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Added to Cart" message:@"Some items are added for time being!" delegate:self cancelButtonTitle:@"View Cart" otherButtonTitles:@"", nil];
    
        UILabel *buttonTitle = [[UILabel alloc] initWithFrame:CGRectMake(148, 102, 125, 40)];
        buttonTitle.text = @"Continue Shopping";
        buttonTitle.font = [UIFont boldSystemFontOfSize:15];
        buttonTitle.textColor = [UIColor whiteColor];
        buttonTitle.textAlignment = UITextAlignmentCenter;
        buttonTitle.backgroundColor = [UIColor clearColor];
        buttonTitle.numberOfLines = 2;
        [alert addSubview:buttonTitle];
        alert.tag = 20;
        [buttonTitle release];
        [alert show];
    

    You can use it anyway....