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