前言
现在一般使用的都是UIAlertViewController
,但是想着写这个来记录一下UIAlertView
的使用,将里面的message
靠左显示
代码如下:
NSString *message = @" 将把原账户以下数据迁移到现\n 有账户\n\n 1、你的计划\n 2、笔记数据\n 3、已报名的活动\n 4、余额\n 5、你的收藏\n 6、你的书单\n 7、你的关注列表\n\n 数据迁移后,将删除原账户\n";
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"账户数据迁移确认" message:message delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1){
UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 240, [UILabel getHeightOfW:240 andText:message andFontSize:15 andLineSpacing:0])];
textLabel.font = [UIFont systemFontOfSize:15];
textLabel.lineBreakMode = NSLineBreakByWordWrapping;
textLabel.numberOfLines = 0;
textLabel.textAlignment = NSTextAlignmentLeft;
textLabel.text = message;
[alertView setValue:textLabel forKey:@"accessoryView"];
alertView.message = @"";
}else{
NSInteger count = 0;
for(UIView * view in alertView.subviews){
if([view isKindOfClass:[UILabel class]]){
count ++;
if (count == 2) { //仅对message左对齐
UILabel *label = (UILabel*) view;
label.textAlignment = NSTextAlignmentLeft;
}
}
}
}
[alertView show];