AlertView-iOS8中未显示多行语句

AlertView-iOS8中未显示多行语句,ios8,Ios8,我想在UIAlertview上显示一些左对齐和中对齐的多语句,但这段代码适用于ios 7,即使它适用于ios 8,但最后一个标签没有显示 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSString *equipmentString =@"100114 Mica Unit 5 and 6

我想在UIAlertview上显示一些左对齐和中对齐的多语句,但这段代码适用于ios 7,即使它适用于ios 8,但最后一个标签没有显示

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSString *equipmentString =@"100114 Mica Unit 5 and 6";
    NSString *projectString =@"01-130156 FORD-FIVEHUNDREDSEL";
    NSString *employeeString =@"00167293 Blake Linfield";
    NSString *lastInspectedDate=@"28-Aug-2014";
    NSString *lastInspectionDay=@"Thursday";
    NSString *title=@"Proceed to inspection?";



    UIView *alertContainerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 271, 150)];

    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, CGRectGetWidth(alertContainerView.frame) - 20, 20)];
    label1.textAlignment =  NSTextAlignmentCenter;
    label1.font = [UIFont boldSystemFontOfSize:14.0f];
    label1.text = title;
    [alertContainerView addSubview:label1];

    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(label1.frame) + 2, CGRectGetWidth(alertContainerView.frame) - 20, 20)];
    label2.textAlignment =  NSTextAlignmentLeft;
    label2.font = [UIFont systemFontOfSize:14.0f];
    label2.text = equipmentString;
    label2.lineBreakMode = NSLineBreakByTruncatingTail;
    label2.numberOfLines = 1;
    [alertContainerView addSubview:label2];

    UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(label2.frame) + 2, CGRectGetWidth(alertContainerView.frame) - 20, 20)];
    label3.textAlignment =  NSTextAlignmentLeft;
    label3.font = [UIFont systemFontOfSize:14.0f];
    label3.text = projectString;
    label3.lineBreakMode = NSLineBreakByTruncatingTail;
    label3.numberOfLines = 1;
    [alertContainerView addSubview:label3];

    UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(label3.frame) + 2, CGRectGetWidth(alertContainerView.frame) - 20, 20)];
    label4.textAlignment =  NSTextAlignmentLeft;
    label4.font = [UIFont systemFontOfSize:14.0f];
    label4.text = employeeString;
    label4.lineBreakMode = NSLineBreakByTruncatingTail;
    label4.numberOfLines = 1;
    [alertContainerView addSubview:label4];

    UILabel *label5=[[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(label4.frame)+2, CGRectGetWidth(alertContainerView.frame)-20, 20)];
    UIFont* boldFont = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
    label5.textAlignment = NSTextAlignmentCenter;
    label5.font = [UIFont systemFontOfSize:14.0f];
    label5.text = lastInspectedDate;
    [label5 setFont:boldFont];
    label5.lineBreakMode = NSLineBreakByTruncatingTail;
    label5.numberOfLines = 1;
    [alertContainerView addSubview:label5];

    UILabel *label6=[[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(label5.frame)+2, CGRectGetWidth(alertContainerView.frame)-20, 20)];
    UIFont* boldFont1 = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
    label6.textAlignment = NSTextAlignmentCenter;
    label6.font = [UIFont systemFontOfSize:14.0f];
    label6.text = lastInspectionDay;
    [label6 setFont:boldFont1];
    label6.lineBreakMode = NSLineBreakByTruncatingTail;
    label6.numberOfLines = 1;
    [alertContainerView addSubview:label6];

   UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:nil cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
    [alertView setValue:alertContainerView forKey:@"accessoryView"];

    [alertView show];
}

最后一个标签在ios 8中没有显示,但ios 7使用的是相同的代码。请有人帮助我问题出在哪里。

您可以尝试此代码

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Alrt" message:@"This is the Message" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancelAction = [UIAlertAction
                                       actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action")
                                       style:UIAlertActionStyleCancel
                                       handler:^(UIAlertAction *action)
                                       {
                                           NSLog(@"Cancel action");
                                       }];

        UIAlertAction *okAction = [UIAlertAction
                                   actionWithTitle:NSLocalizedString(@"OK", @"OK action")
                                   style:UIAlertActionStyleDefault
                                   handler:^(UIAlertAction *action)
                                   {
                                       NSLog(@"OK action");
                                   }];

        [alertController addAction:cancelAction];
        [alertController addAction:okAction];

        [self presentViewController:alertController animated:YES completion:nil];

不,这对我没有帮助,因为这是在iOS 8中创建UIAlertView的唯一方法,但我需要在UIAlertView上添加多个标签并进行一些对齐。