UITableView Cell Font Size

Is there a way to make the text “automatically” smaller if the text on one line is longer than it can fit?

+3
source share
2 answers

Yes:

UILabel *myLabel = /* init the label */
myLabel.adjustsFontSizeToFitWidth = YES;

For iOS 7:

myLabel.minimumScaleFactor = 0.5;  // Float from 0 to 1; as a scale of init size.

For iOS 6 and Prior:

myLabel.minimumFontSize = 10;  // Float value, in pixels (int value recom'd).

You can read more at Apple UILabeldocs .

+7
source

I know that several years have passed, but when I found this answer, I also found a simpler way. This is instead of creating your own label, use it in the cell.

cell.textLabel.adjustsFontSizeToFitWidth = YES;
cell.textLabel.minimumScaleFactor = 0.6;
+4
source

Source: https://habr.com/ru/post/1717979/


All Articles