- (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