None of the methods listed below give exact visible text boundaries in Cocoa. How do we get it?
NSString
boundingRectWithSize:options:attributes:
NSAttributedString
boundingRectWithSize:options:
NSLayoutManager
usedRectForTextContainer:
To illustrate this, here is a screenshot of the result of using the second method above, as shown in this code snippet example .
Here's the solution I have encoded. Any suggestions for improvement are welcome. code snippet: http://pastebin.com/qJMKwvauScreenshot: http://ScrnSht.com/jskyqs
Actually, from a typographic point of view, the field is correct, but the font exceeds its own border. You can try the NSStringDrawingUsesDeviceMetrics option, which uses glyph borders instead of typographic borders.
NSStringDrawingUsesDeviceMetrics