2

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

Community
  • 1
  • 1
Nag_iphone
  • 967
  • 7
  • 22

4 Answers4

2

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....

kallol
  • 319
  • 1
  • 13
1

UIAlertView doesn't support multi-line buttons. One option would be to just use "Continue" instead of "Continue Shopping" as the button title, otherwise you'd have to use a custom alert view component, e.g. CODialog (you might have to customize it a bit to allow multi-line buttons, but it should be easy).

omz
  • 53,243
  • 5
  • 129
  • 141
0
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 buttons] objectAtIndex:1] setLineBreakMode:UILineBreakModeWordWrap];
[alert show];

This code does exactly what you need. Note, however that

  1. - [UIAlertView buttons] is undocumented
  2. - [UIButton setLineBreakMode] is deprecated. You can however, replace it with

    [button.titleLabel setLineBreakMode] which is essentially the same.

Oleg Trakhman
  • 2,082
  • 1
  • 17
  • 35
0

I think you can try to set numbersOfLine property to label on button. But i don`t know will apple aprove that.

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];
NSArray *subviewsArray = [alert subviews];
    for (UIView *subview in subviewsArray) {
        if ([subview isKindOfClass:[UIButton class]]) {
            NSArray *btnSubviews = [subview subviews];
            for (UIView *btnSubview in btnSubviews) {
                if ([btnSubview isKindOfClass:[UILabel class]]) {
                    UILabel *title = (UILabel *)btnSubview;
                    title.numberOfLines = 2;
                }
            }
        }
    }
alert.tag = 20;
[alert show];
[alert release];
Moonkid
  • 881
  • 7
  • 17