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];
相關文章
相關標籤/搜索