UIAlertView 左对齐 iOS7及iOS6不同处理

 之前看到很多通过-(void)willPresentAlertView:(UIAlertView *)alertView来修改alertView的subview的代码,但是在iOS7以上的系统没有作用,查了很久的资料也没有说明,有想过自己重写一个,但是后来在csdn闪下到一段代码http://download.csdn.net/download/folish_audi/7543541,和自己之前写的相结合一下,就都支持了。

              

 NSString *content =  @"1、增加白菜党等特色标签筛选\n2、增加频道热度排行\n3、增加夜间模式\n4Material design风格优化\n5、滑动返回优化\n6、其他bug修复"};

               NSString *message = [[NSStringalloc] initWithFormat:@"发现新版本1.1,是否更新?\n本次更新内容:\n%@", content];

                 

                

               UIAlertView  *alert = [[UIAlertViewalloc] initWithTitle:@"立即更新"message:message

                                                 delegate:self

                                        cancelButtonTitle:@"暂不更新"

                                        otherButtonTitles:@"立即更新",nil];

                

               //如果你的系统大于等于7.0

                if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)

                {

                    CGSize size = [messagesizeWithFont:[UIFontsystemFontOfSize:15]constrainedToSize:CGSizeMake(240,400) lineBreakMode:NSLineBreakByTruncatingTail];

                    

                   UILabel *textLabel = [[UILabelalloc] initWithFrame:CGRectMake(0, -20,240, size.height)];

                    textLabel.font = [UIFontsystemFontOfSize:15];

                    textLabel.textColor = [UIColorblackColor];

                    textLabel.backgroundColor = [UIColorclearColor];

                    textLabel.lineBreakMode =NSLineBreakByWordWrapping;

                    textLabel.numberOfLines =0;

                    textLabel.textAlignment =NSTextAlignmentLeft;

                    textLabel.text = message;

                    [alertsetValue:textLabel forKey:@"accessoryView"];

                     

                    alert.message =@"";

                }else{

                   NSInteger count = 0;

                   for( UIView * viewin alert.subviews )

                    {

                       if( [view isKindOfClass:[UILabelclass]] )

                        {

                            count ++;

                           if ( count == 2 ) { //仅对message左对齐

                               UILabel* label = (UILabel*) view;

                                label.textAlignment =NSTextAlignmentLeft;

                            }

                        }

                    }

                }

                [alertshow];


你可能感兴趣的:(ios7,uialertview,左对齐)