How to calculate actual font point size in iOS 7 (not the bounding rectangle)?

I have the same problem, I need to know the actual size to make that the others UILabels in my UIView match.

I know that it’s not a perfect solution, but perhaps it’s useful for you.

My solution is: instead of use adjustsFontSizeToFitWidth I calculate “manually” the size.

CGSize initialSize = [_label.text sizeWithAttributes:@{NSFontAttributeName:_label.font}];
while ( initialSize.width > _label.frame.size.width ) {
    [_label setFont:[_label.font fontWithSize:_label.font.pointSize - 1]];
    initialSize = [_label.text sizeWithAttributes:@{NSFontAttributeName:_label.font}];
}
CGFloat actualSize = _label.font.pointSize;

Leave a Comment