iOS UIAlertView 文字對其方式 文字大小 設置方法


- (void) willPresentAlertView:(UIAlertView *)alertView
{
   for (UIView *subViewin alertView.subviews)
    {
       UILabel *tmpLabel = (UILabel *)subView;
        tmpLabel.textAlignment =NSTextAlignmentLeft;
    }
}

在iOS7.0之前通過以上方法進行設置Label對其和文字大小,但是到了iOS7.0以后以上方法都無效了

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"測試換行"
                                                               message:nil
                                                              delegate:self
                                                     cancelButtonTitle:nil
                                                     otherButtonTitles:@"知道了", nil];

            CGSize size = [self.messageString sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(240, 1000) lineBreakMode:NSLineBreakByTruncatingTail];
            
            UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 240, size.height)];
            textLabel.font = [UIFont systemFontOfSize:15];
            textLabel.textColor = [UIColor blackColor];
            textLabel.backgroundColor = [UIColor clearColor];
            textLabel.lineBreakMode = NSLineBreakByWordWrapping;
            textLabel.numberOfLines = 0;
            textLabel.textAlignment = NSTextAlignmentLeft;
            textLabel.text = self.messageString;
            [tmpAlertView setValue:textLabel forKey:@"accessoryView"];
            [alertView show];

iOS7.0 通過KVC的方式重寫accessoryView的方法來替換系統的UILabel


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM