如何让 tableview header 调整字体以适合宽度

How to get tableview header to adjust font to fit width

我正在使用以下代码行来调整我的 tableview header 字体。 [[UILabel appearanceWhenContainedIn:[UITableViewHeaderFooterView class], nil] setFont:[UIFont boldSystemFontOfSize:16]];

如何调整此字体以适应宽度?下面的行不起作用? [UILabel setAdjustsFontSizeToFitWidth:YES];

你有几种解决方法

  1. 使用自动调整大小,如果您不熟悉这需要一些时间

  2. 在 NSString 对象上使用以下方法查找具有指定大小的结果字符串的大小并找到合适的字体大小,如

[@"CheckString" sizeWithFont:[UIFont boldSystemFontOfSize:16]];