• 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: Clark Williams <email@hidden>
  • Date: Thu, 26 Jan 2012 16:53:15 -0800

The solution was simpler than I thought.

something.h file a line like:
	NSMutableAttributedString *theAS;
	int charIndex = 0;

something.m file in an init method somewhere:
    NSMutableAttributedString *theAS = [[NSMutableAttributedString alloc] initWithString:@"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"];
    charIndex = 0;

something.m file in an action or message received method:
    if ( charIndex < [ [ theAS string ] length ] ) {
    	NSRange nxt2Chars = NSMakeRange ( charIndex, 2 );
    	[ theAS beginEditing ];
    	[ theAS addAttribute: NSBackgroundColorAttributeName
                               value: [ NSColor orangeColor ]
                              range: nxt2Chars ];
	[ theAS endEditing ];
	[ currentDataTextBox setAttributedStringValue:theAS ];
    }
    charIndex += 2;

Depending on how you implement this you may have to turn off the previous selection as well in the NSMutableString.

Thanks again to all who assisted!
Clark Williams

<bandwidth compression>
 _______________________________________________
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: Ross Carter <email@hidden>
References: 
 >Highlighting chars in an NSTextField? (From: Clark Williams <email@hidden>)
 >Re: Highlighting chars in an NSTextField? (From: Fritz Anderson <email@hidden>)
 >Re: Highlighting chars in an NSTextField? (From: Christiaan Hofman <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