Re: NSTableView
Re: NSTableView
- Subject: Re: NSTableView
- From: mmalcolm crawford <email@hidden>
- Date: Thu, 30 May 2002 14:44:35 -0700
On Thursday, May 30, 2002, at 03:28 AM, Joe Morris wrote:
If I had a table that had a list of names in it and I wanted all the
names that contained a 'd' to appear red instead of
black like the rest of the names.
Finally sitting at my home computer, this is the code I used (feel free
to copy :-)). Right now I've commented out the bolded font, but you
can see easily how to make that switch.
Umm, this has been answered a couple of times already...
//used to display groups in bold
- (void)tableView:(NSTableView*)sender willDisplayCell:(NSCell*)cell
forTableColumn:(NSTableColumn*)column row:(int)row {
NSColor *txtColor = [NSColor blueColor];
NSFont *txtFont = [NSFont /*boldS*/systemFontOfSize:13];
NSDictionary *txtDict = [NSDictionary
dictionaryWithObjectsAndKeys:txtFont,
NSFontAttributeName, txtColor, NSForegroundColorAttributeName,
nil];
NSString *string = [self tableView:sender
objectValueForTableColumn:column row:row];
NSAttributedString *attrStr = [ [ [NSAttributedString alloc]
initWithString:string attributes:txtDict] autorelease];
[cell setAttributedStringValue:attrStr];
... and this, as Ondra appears to have mentioned back in April, is not
the best way to achieve the desired result.
You don't have to create your own attributed string, you can leave it up
to the cell, as per my example May 26:
- (void)tableView:(NSTableView *)tableView
willDisplayCell:(id)cell
forTableColumn:(NSTableColumn *)tableColumn row:(int)row
{
if (<test>) {
[cell setTextColor:[NSColor redColor]];
}
// strictly should also have:
else {
[cell setTextColor:[NSColor blackColor]];
}
}
mmalc
_______________________________________________
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.