minimumFontSize 自iOS6起已弃用 . 此外,仅当 numberOfLines 设置为1时,adjustsFontSizeToFitWidth才有效.UILabel不会跨多行调整文本大小,因为在缩小字体时处理换行符时存在歧义 .
使用 minimumScaleFactor 设置文本应缩放的最小大小 .
以下代码将使用字体大小为20的属性字符串填充 UILabel ,并将其缩小一半,最小大小为10 .
self.label.lineBreakMode = NSLineBreakByTruncatingTail;
NSMutableAttributedString *hogan = [[NSMutableAttributedString alloc] initWithString:@"Presenting the great... Hulk Hogan! Presenting the great... Hulk Hogan! Presenting the great... Hulk Hogan! Presenting the great... Hulk Hogan! Presenting the great... Hulk Hogan! Presenting the great... Hulk Hogan! Presenting the great... Hulk Hogan!"];
[hogan addAttribute:NSFontAttributeName
value:[UIFont systemFontOfSize:20.0]
range:NSMakeRange(0, [hogan length])];
[self.label setAttributedText:hogan];
self.label.adjustsFontSizeToFitWidth = YES;
self.label.numberOfLines = 1;
self.label.minimumScaleFactor = 0.5;