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 protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to