How do I add color to a range in a NSMutableAttributedString?
ksv web developer Feb 5, 2006 #2 Look in the Attributed Strings Programming Guide. NSAttributedString has the method Code: - (void)addAttribute:(NSString *)name value:(id)value range:(NSRange)aRange which can be used like this to make letters 3-5 in the string red: Code: [string addAttribute:NSForegroundColorAttributeName value:[NSColor redColor] range:NSMakeRange(3, 2)];
Look in the Attributed Strings Programming Guide. NSAttributedString has the method Code: - (void)addAttribute:(NSString *)name value:(id)value range:(NSRange)aRange which can be used like this to make letters 3-5 in the string red: Code: [string addAttribute:NSForegroundColorAttributeName value:[NSColor redColor] range:NSMakeRange(3, 2)];
J <Jacob> Registered Feb 5, 2006 #3 This is the error I get: 2006-02-05 21:51:16.292 <ProjectName>[1549] *** -[NSBigMutableString addAttribute:value:range:]: selector not recognized And this is my code: NSMutableAttributedString *code=[editor_code string]; ... [code addAttribute:NSForegroundColorAttributeName value:[NSColor redColor] range:NSMakeRange(3, 2)]; [editor_code setString:code]; ------------------------- I also have another question, to get a NSTextView's contents as a string is this what you would do: '[anNSTextView string];' And to set it's contents to a string: '[anNSTextView setString:aString];'? Would this be any different if I were to use an NSMutableAttributedString? Any help is more than welcome.
This is the error I get: 2006-02-05 21:51:16.292 <ProjectName>[1549] *** -[NSBigMutableString addAttribute:value:range:]: selector not recognized And this is my code: NSMutableAttributedString *code=[editor_code string]; ... [code addAttribute:NSForegroundColorAttributeName value:[NSColor redColor] range:NSMakeRange(3, 2)]; [editor_code setString:code]; ------------------------- I also have another question, to get a NSTextView's contents as a string is this what you would do: '[anNSTextView string];' And to set it's contents to a string: '[anNSTextView setString:aString];'? Would this be any different if I were to use an NSMutableAttributedString? Any help is more than welcome.