Re: Highlighting chars in an NSTextField?
Re: Highlighting chars in an NSTextField?
- Subject: Re: Highlighting chars in an NSTextField?
- From: Jens Alfke <email@hidden>
- Date: Thu, 26 Jan 2012 16:59:52 -0800
On Jan 26, 2012, at 2:51 PM, Clark Williams wrote: Perhaps Fritz's 5th point is the way to go although it seems to me that a message such as: [someNSTextField setTextHighlighted: (BOOL)highlightOnOrOff: (NSColor)color: (NSInteger)startPosition: (NSInteger)endPosition]; or perhaps: [someNSTextField setTextHighlighted: (BOOL)highlightOnOrOff: (NSColor)color: (NSRange) range]; would be useful.
That sort of highlighting is more an attribute of the text than of the control. I have used attributed strings in the past (especially to do HTML and RTF) but it seems to me that attributed strings also saw the receivers as entire entities so I don't see how I might change the background of just a small selection of text. I can't figure out what you mean by "saw the receivers as entire entities".
The point of attributed strings is that they associate arbitrary attributes with ranges of characters in the text. (The class actually doesn't care what those attributes are or mean; it's AppKit's text system that interprets their meanings.) What you want to do is make an NSMutableAttributedString on your text, then set the value of the NSBackgroundColorAttributeName to the appropriate NSColor over a specific NSRange of characters. The API to do that should be pretty clear. (You will probably also want to set the NSFontAttributeName over the entire text to control what font it's displayed in.)
—Jens
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden