None of the methods listed below give the exact visible bounds of a text in Cocoa. How do we obtain that?
NSString
boundingRectWithSize:options:attributes:
NSAttributedString
boundingRectWithSize:options:
NSLayoutManager
usedRectForTextContainer:
To illustrate this, here's a screenshot of the result of using the second method above as shown in this sample code snippet.
Actually, from the typographic point of view, the box is correct, but the font exceeds is own bound. You can try the option NSStringDrawingUsesDeviceMetrics, that uses glyph bounds instead of typographic bounds.
NSStringDrawingUsesDeviceMetrics
2.1m questions
2.1m answers
60 comments
57.0k users