是的:
UILabel *myLabel = /* init the label */
myLabel.adjustsFontSizeToFitWidth = YES;
Run Code Online (Sandbox Code Playgroud)
对于iOS 7:
myLabel.minimumScaleFactor = 0.5; // Float from 0 to 1; as a scale of init size.
Run Code Online (Sandbox Code Playgroud)
对于iOS 6和Prior:
myLabel.minimumFontSize = 10; // Float value, in pixels (int value recom'd).
Run Code Online (Sandbox Code Playgroud)
您可以在Apple的UILabel文档中阅读更多内容.
我知道已经有几年了,但是当我找到这个答案时,我也发现了一种更简单的方法.这不是创建自己的标签,而是使用单元格中的标签.
cell.textLabel.adjustsFontSizeToFitWidth = YES;
cell.textLabel.minimumScaleFactor = 0.6;
Run Code Online (Sandbox Code Playgroud)