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

Highlighting chars in an NSTextField?


  • Subject: Highlighting chars in an NSTextField?
  • From: Clark Williams <email@hidden>
  • Date: Thu, 26 Jan 2012 11:31:42 -0800

I have a NSTextField with a string displayed. I want to hightlight the 1st 2 chars then the next 2, then the next 2, etc.
I tried the following code:

but does not seem to work. At least it doesn't highlight anything.
[currentDataTextBox setStringValue:@"AaBbCcDdEeFfGgHh"];
NSCell* currentCell = [currentDataTextBox cell];
NSView *currentView4Cell = [currentCell controlView];
NSRect currentRect = [currentDataTextBox bounds];
// guess at the points/character
double pointsPerChar = currentRect.size.width / [[currentDataTextBox stringValue] length];
NSLog ( @"pt/char: %f",  pointsPerChar );
currentRect.origin.x  +=  0.0; // bump this to change the origin in loop
currentRect.size.width = pointsPerChar * 2.0;
[currentCell highlight:YES withFrame:currentRect inView:currentView4Cell];

 

Is this the wrong approach?
Pointers to code samples, suggestions, etcetera, would be appreciated.
TIA
Clark Williams

 _______________________________________________
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: Fritz Anderson <email@hidden>
    • Re: Highlighting chars in an NSTextField?
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Re: A reproducible crash
  • Next by Date: Re: Highlighting chars in an NSTextField?
  • Previous by thread: Re: A reproducible crash
  • Next by thread: Re: Highlighting chars in an NSTextField?
  • Index(es):
    • Date
    • Thread