• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Finding bounding rect of substring inside a wrapped string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finding bounding rect of substring inside a wrapped string


  • Subject: Re: Finding bounding rect of substring inside a wrapped string
  • From: Martin Wierschin <email@hidden>
  • Date: Wed, 7 Jan 2009 00:15:41 -0800

The title basically says it. I have a string (not very long; less than 150 characters) that is wrapped inside an NSTextField (a label). I want to find the bounding rects of a couple substrings, so that I can overlay them with an NSButton. I've been searching around, and I've found a promising lead with NSLayoutManager's "- boundingRectForGlyphRange:inTextContainer:", but I've never used an NSTextContainer before and am not sure how they work.

Would this be the proper way to do it? How can I create an NSTextContainer that contains a string?

It might be better to ask what you're trying to accomplish with the buttons. Do you really want to add stock buttons on top of the text, or do you just need hit testing or a way to display the text differently? It's probably worth mentioning that even if you did add the buttons, editing the text field would be problematic because the NSTextField swaps in a field editor view, which I bet would obscure or interact weirdly with your buttons.


Depending on what you're actually trying to do here, it might be better to insert a custom NSTextAttachment into your content, switch to using an NSTextView (which provides access to NSTextContainer and friends), or build your own view subclass that draws text using an NSLayoutManager directly.

~Martin
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Finding bounding rect of substring inside a wrapped string (From: Dave DeLong <email@hidden>)

  • Prev by Date: Re: [iPhone] Search control like in App Store
  • Next by Date: Re: [iPhone] Search control like in App Store
  • Previous by thread: Finding bounding rect of substring inside a wrapped string
  • Next by thread: Localize Attributed Strings?
  • Index(es):
    • Date
    • Thread