trss
trss

Reputation: 943

How do we measure visible bounds of text in Cocoa?

None of the methods listed below give the exact visible bounds of a text in Cocoa. How do we obtain that?

To illustrate this, here's a screenshot of the result of using the second method above as shown in this sample code snippet.

Upvotes: 5

Views: 1583

Answers (2)

trss
trss

Reputation: 943

Here's the solution I coded up. Any suggestions for improvements are most welcome.
code snippet: http://pastebin.com/qJMKwvau
screenshot: http://ScrnSht.com/jskyqs

Upvotes: 1

Matthias
Matthias

Reputation: 8180

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.

Upvotes: 4

Related Questions