UIAlertView 左对齐 iOS7及iOS6不一样处理

 以前看到不少经过-(void)willPresentAlertView:(UIAlertView *)alertView来修改alertView的subview的代码,可是在iOS7以上的系统没有做用,查了好久的资料也没有说明,有想过本身重写一个,可是后来在csdn闪下到一段代码http://download.csdn.net/download/folish_audi/7543541,和本身以前写的相结合一下,就都支持了。app

              

 NSString *content =  @"一、增长白菜党等特点标签筛选\n二、增长频道热度排行\n三、增长夜间模式\n四、Material design风格优化\n五、滑动返回优化\n六、其余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];
相关文章
相关标签/搜索