Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

  • NSString's boundingRectWithSize:options:attributes:
  • NSAttributedString's boundingRectWithSize:options:
  • NSLayoutManager's usedRectForTextContainer:

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
771 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...