我有一个UILabel,他的文字大小有属性
title.adjustsFontSizeToFitWidth = YES;
这使我无法使用标准方法来调整 UILabel 的大小。我在这里的另一篇文章中读到我应该使用该功能
sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode
来自这个答案:当 -adjustsFontSizeToFitWidth 设置为 YES 时,如何计算 UILabel 的字体大小?
现在,我不知道如何使它工作..这是实际的代码
UIFont *font = [UIFont fontWithName:@"Marker Felt" size:200];
UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, width, 20.0)];
title.text = @"this is a long title that should be resized";
title.font = font;
title.numberOfLines = 1;
title.adjustsFontSizeToFitWidth = YES;
CGFloat pointSize = 0.0;
CGSize size = [title.text sizeWithFont:font
minFontSize:title.minimumFontSize
actualFontSize:&pointSize
forWidth:width
lineBreakMode:title.lineBreakMode];
title.frame = CGRectMake(title.frame.origin.x,
title.frame.origin.y,
size.width,
size.height);
UILabel 被错误地调整大小,好像字体大小仍然是 200 .. 任何线索?谢谢!