• 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: Displaying a table entry in Bold
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Displaying a table entry in Bold


  • Subject: Re: Displaying a table entry in Bold
  • From: Joe Morris <email@hidden>
  • Date: Fri, 19 Apr 2002 15:14:31 -0400

Eric was very close, and led me to the solution, but I thought I'd post the solution code I got out of NSCell:

- (void)tableView:(NSTableView*)sender willDisplayCell:(NSCell*)cell forTableColumn:(NSTableColumn*)column row:(int)row
{
NSColor *txtColor = [NSColor blueColor];
NSFont *txtFont = [NSFont boldSystemFontOfSize: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];
}

This is with the self object being set up as the tableView's delegate and data source (both by dragging connections in Interface Builder). The beauty of this function is you don't even have to delve into getting what the cell should display text-wise, you can just use the function you've already implemented for that very purpose. :-)

Thanks again!

-Joe

On Friday, April 19, 2002, at 10:44 AM, Eric Peyton wrote:

In your

- (void)tableView:(NSTableView*)sender willDisplayCell:(NSCell*)cell forTableColumn:(NSTableColumn*)column row:(int)row

You can do something like this ...

NSFont *font = nil;
NSFont *listFont = <Whatever font you want to be bolded goes here>;
NSMutableAttributedString* string = <whatever text you want goes here> - example [[[NSAttributedString alloc] initWithString:@"HeyThere"] autorelease];

font = [[NSFontManager sharedFontManager] convertFont:listFont toHaveTrait:NSBoldFontMask];
[string addAttribute:NSFontAttributeName value:(font ? font : listFont ) range:range];
[cell setAttributedStringValue:string];

Eric



On Friday, April 19, 2002, at 08:59 AM, Joe Morris wrote:

So I have a standard table with a data source set up, passing strings to the table for displaying, and I would like to selectively display some of the table rows in bold. Does anyone know how to do that?

Thanks! :-)

-Joe

"Anyone who lives within their means
suffers from a lack of imagination."
-Oscar Wilde
_______________________________________________
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.
_______________________________________________
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.

  • Follow-Ups:
    • Re: Displaying a table entry in Bold
      • From: Ondra Cada <email@hidden>
References: 
 >Re: Displaying a table entry in Bold (From: Eric Peyton <email@hidden>)

  • Prev by Date: Re: programmatically switching the keyboard layout
  • Next by Date: Re: Time & Date Control?
  • Previous by thread: Re: Displaying a table entry in Bold
  • Next by thread: Re: Displaying a table entry in Bold
  • Index(es):
    • Date
    • Thread