• 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: Highlighting chars in an NSTextField?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Highlighting chars in an NSTextField?
      • From: Clark Williams <email@hidden>
References: 
 >Highlighting chars in an NSTextField? (From: Clark Williams <email@hidden>)
 >Re: Highlighting chars in an NSTextField? (From: Jens Alfke <email@hidden>)
 >Re: Highlighting chars in an NSTextField? (From: Clark Williams <email@hidden>)

  • Prev by Date: Re: Highlighting chars in an NSTextField?
  • Next by Date: Re: Highlighting chars in an NSTextField?
  • Previous by thread: Re: Highlighting chars in an NSTextField?
  • Next by thread: Re: Highlighting chars in an NSTextField?
  • Index(es):
    • Date
    • Thread