Re: Syntax Highlighting Prob - Adding Other Colors.
Re: Syntax Highlighting Prob - Adding Other Colors.
- Subject: Re: Syntax Highlighting Prob - Adding Other Colors.
- From: "M. Uli Kusterer" <email@hidden>
- Date: Sun, 11 May 2003 20:52:12 +0200
while (area.length) {
found = [string rangeOfString:@"Mike"
options:NSCaseInsensitiveSearch
range:area];
if (found.location == NSNotFound) break;
[textStorage addAttribute:NSForegroundColorAttributeName
value:blue
range:found];
area.location = NSMaxRange(found);
area.length = length - area.location;
This code is part of a bigger piece (obvious). What I want to succeed
with is, adding another color, and text. I know I need to use if, else
if etc. But, I've tried and just can't figure it out. So to summarize,
say I want the word George in red, how would I do that? Currently I
have Mike in blue. I would really appreciate the help!
You plrobably want to put a second loop around the first one that
resets range to its initial value (so the search starts again at the
start of your text), and use an NSString* variable instead of @"Mike"
and an NSColor* variable instead of blue. Then set these variables to
the string and color you want to use this time through the loop. In
pseudocode:
NSColor colors[15]
NSString strings[15]
for( x = 0; x < 15; x++ )
{
range.length := textStorage.length
range.offset := 0
currColor := colors[x]
currString := strings[x]
while( range.length )
{
found := [string rangeOfString: currString]
if( found )
[textStorage addAttribute:FgColor value:currColor]
}
}
You get the picture.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.