您的位置:首页 > 产品设计 > UI/UE

UIAlertView message 居左对齐 显示ios7以后不能用的启发

2013-11-05 11:46 435 查看
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:self.version message:versionConnet
delegate:self cancelButtonTitle:@"取消"otherButtonTitles:@"更新",nil];
UILabel *label = [alert.subviews objectAtIndex:1];
label.textAlignment = UITextAlignmentLeft;
[alert show];

以上方法导致在ios7中直接挂了。
建议程序采用以下写法,虽然在ios7中这样也不能改变,但对程序的兼容性和容错性提高了很多

//message居左对齐
NSArray *subViewArray = alert.subviews;
for(int x=0;x<[subViewArray count];x++){
if([[[subViewArray objectAtIndex:x] class] isSubclassOfClass:[UILabel class]])
{
UILabel *label = [subViewArray objectAtIndex:x];
label.textAlignment = UITextAlignmentLeft;
}
}

ios7的解决方法:https://github.com/wimagguc/ios-custom-alertview
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: