我想在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一起工作,请帮助我解决问题。
答案 0 :(得分:-1)
您可以试用此代码
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];