Re: Highlight color of a NSTableView row
Re: Highlight color of a NSTableView row
- Subject: Re: Highlight color of a NSTableView row
- From: Ben Lachman <email@hidden>
- Date: Sat, 12 Apr 2008 23:40:30 -0400
Sorry, perhaps I should have been a bit more specific. That
implementation both overrides highlightColorWithFrame: and
drawWithFrame:. As you noticed, the draw with draw bit just just
draws the text white if the cell is selected. This is nice for dark
selection highlight colors and most of Apple's iApps that contain
table views do it. To remove that behavior just remove:
NSColor *oldColor = [self textColor];
[self setTextColor:[NSColor alternateSelectedControlTextColor]];
[super drawWithFrame:cellFrame inView:controlView];
[self setTextColor:oldColor];
Which saves the original color, set the color of the text to white,
draws it and then restores the original color. Calling super's draw
method just draws the cell as it would normally given the current
settings (color, title, etc.).
HTH,
->Ben
--
Ben Lachman
Acacia Tree Software
http://acaciatreesoftware.com
email@hidden
740.590.0009
On Apr 12, 2008, at 1:23 PM, Eric Gorr wrote:
On Apr 11, 2008, at 12:21 AM, Ben Lachman wrote:
I do something like this:
@implementation HilightingTextFieldCell
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)
controlView {
if( [self isHighlighted] ) {
NSColor *oldColor = [self textColor];
[self setTextColor:[NSColor alternateSelectedControlTextColor]];
[super drawWithFrame:cellFrame inView:controlView];
[self setTextColor:oldColor];
} else {
[super drawWithFrame:cellFrame inView:controlView];
}
}
- (NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView:
(NSView *)controlView {
return nil;
}
@end
So, based on your code, I have written this...
@implementation CustomHighlightTextFieldCell
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
NSColor *evenColor = [NSColor colorWithCalibratedRed:.9 green:0
blue:0 alpha:1.0];
if ( [self isHighlighted] ) {
[evenColor set];
NSRectFill( cellFrame );
NSColor *oldColor = [self textColor];
[self setTextColor:[NSColor blackColor]];
[super drawWithFrame:cellFrame inView:controlView];
[self setTextColor:oldColor];
}
else {
[super drawWithFrame:cellFrame inView:controlView];
}
}
- (NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView:
(NSView *)controlView
{
return nil;
}
@end
I just want to draw the entire cell with a background color with
black text.
For a selected row, what I get is a cell drawn with the background
color, but white text. I cannot figure out how to get the text
drawn with a black color.
Will I need to replace:
[super drawWithFrame:cellFrame inView:controlView];
with my own code to draw the text?
At this point, actually seeing my specific case might be helpful...
I have placed my project at:
http://ericgorr.net/acc.zip
The application is a (not entirely complete) calculator for the
board game Advanced Civilization ( http://www.boardgamegeek.com/
game/177 ). What it does is keep track of what civ. cards you have
purchased throughout the game and keep track of the current cost of
the cards which you can still purchase. Each row corresponds to one
of the civ. cards.
What I have written, which only uses highlightSelectionInClipRect
to control the highlighting, has nearly all of the highlighting I
want.
1. Row, in groups of three, have either a light blue or white
background, if the card has not been purchased (<rant>I _hate_ the
look of the alternating light blue & white...groups of three is
_vastly_ superior</rant>)
2. If a card has been purchased, it's background is yellow.
3. For #1 & #2, the text remains black - my guess as to why this is
the case is that the process of highlighting a selected row changes
the text to white and if a row is not selected, it get the black
text with either the light blue, white or yellow background.
4. When I select a row, it's get the highlight color specified by
the system preference - the default blue highlight color on my
machine.
5. There is no space between the columns
6. If two cards have been purchased and are in adjacent rows, there
is no space between the rows, which have been colored yellow.
The only thing I would like to change about how this is working is
when I select a row of a card which has been purchased, I would
like to use a darker yellow color.
....just a usage note...to be able to purchase a card, first enter
a number (like 200) into the 'Trade Cards' field, this will cause
the purchase button to be enabled. Second, select a row, which
isn't grayed out. Third, press the purchase button.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden