1

In iOS 7 this method became deprecated. The documentation is vague on a replacement and states:

There is no exact alternative for this method. Human interface guidelines discourage changing the font size this way because it leads to an inconsistent user experience. See UILabel as a possible alternative for some use cases.

I found a solution but it ignores that UILabel can shrink text down if needed. There is no minimum font size argument.

Has anyone found an alternative for situations where you really want to calculate the bounding rect size of some text in a label that can shrink in font size when the text is too long?

openfrog
  • 40,201
  • 65
  • 225
  • 373

1 Answers1

1

You got to love Apple's comment on this one...

Seems like your only option is to implement yourself the logic behind the original function using boundingRectWithSize:options:attributes:context: and the detailed description of the deprecated function (under "Discussion").

Using boundingRectWithSize:options:attributes:context: you can specify a UIFont with a specific size, and get the resulted width. Then you can compare the resulted width with your required width. You still need however some trials and errors to determine the actual font size.

HyBRiD
  • 688
  • 4
  • 23