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
1.4m articles
1.4m replys
5 comments
57.0k users