Re: Sizing an image for a tableview cell
Re: Sizing an image for a tableview cell
- Subject: Re: Sizing an image for a tableview cell
- From: Chuck Soper <email@hidden>
- Date: Sun, 25 Jul 2004 10:07:47 -0700
Tito,
You could use the following NSTableView delegate to draw a background color:
- (void)tableView: (NSTableView *)tableView willDisplayCell: (id)cell
forTableColumn: (NSTableColumn *)tableColumn row: (int)rowIndex
{
if (1) { // your test condition here
[cell setDrawsBackground: YES];
[cell setBackgroundColor: [NSColor purpleColor]]; // your color here
} else {
[cell setDrawsBackground: NO];
[cell setBackgroundColor: [NSColor whiteColor]];
}
}
Or, if you have NSCell subclasses then you may need to subclass your
NSTableView and override the method below. If you take this approach
then you won't need to use the delegate method above.
- (void)drawRow:(int)rowIndex clipRect:(NSRect)clipRect
{
if (![self isRowSelected:rowIndex]) {
NSRect cellRect = [self rectOfRow:rowIndex];
if (1) { // your test condition here
[[NSColor purpleColor] set]; // your color here
NSRectFill(NSIntersectionRect(cellRect,clipRect));
} else {
[[NSColor whiteColor] set];
NSRectFill(NSIntersectionRect(cellRect,clipRect));
}
}
//draw row content
[super drawRow:rowIndex clipRect:clipRect];
}
Chuck
At 11:31 AM -0400 7/25/04, Tito Ciuro wrote:
Hello,
I need to set the color of a cell which covers the entire cell bounds.
Each row has a different color, so in tableView:
objectValueForTableColumn: row:, I thought of getting the bounds of a
cell at a given index, create an NSImage with the desired color, and
return the image. The problem is that I cannot seem to obtain the size
of the cell, therefore I cannot create the image.
Any ideas?
Thanks!
-- Tito
_______________________________________________
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.