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

来源:互联网 发布:linux命令echo使用简介 编辑:程序博客网 时间:2024/05/01 14:31

  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] classisSubclassOfClass:[UILabel class]])

            {

                UILabel *label = [subViewArray objectAtIndex:x];

                label.textAlignment = UITextAlignmentLeft;

            }

        }


ios7的解决方法:https://github.com/wimagguc/ios-custom-alertview