Change NSTextField font size to fit

cocoa, fonts, macos, nstextfield, uilabel

Solution

In short: no. You have to do some brute force work to determine a string's -sizeWithAttributes: -boundingRectWithSize:options:attributes: with a given font size (set as an NSFont for NSFontAttributeName).

I'd start with a standard system font size and work down or up from there, depending on whether it's smaller or larger than the desired rectangle.

Problem

Is there anything like the UILabel's `adjustsFontSizeToFitWidth` that can be used with a NSTextField?

Original source

Related problems