NSCell을 상속받아서 만든 Cell을 선택하였을 때 글자 색상 흰색으로 변경
2011/02/08 10:51
NSCell을 상속받아 만든 Cell에서 Cell 선택시 하이라이트 되어지는 곳의 글자 색상이 검은색이면 시각적으로 보기 좋지 않아서 draw될때 선택된 cell이면 글자 색상을 하얀색으로 변경하고 싶을 때 아래와 같이 하면 된다.
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
NSColor *textColor;
NSPoint textPoint;
NSString *bannerTitle;
NSMutableDictionary *textAttributes;
if([self isHighlighted]) {
textColor = [NSColor selectedMenuItemTextColor];
} else {
textColor = [NSColor controlTextColor];
}
if ([[self objectValue] isKindOfClass:[NSString class]]) {
bannerTitle = [self objectValue];
textPoint.x = cellFrame.origin.x + 10;
textPoint.y = cellFrame.origin.y + 12;
textAttributes = [NSMutableDictionary dictionaryWithObjectsAndKeys: textColor,
NSForegroundColorAttributeName, [NSFont systemFontOfSize:14], NSFontAttributeName, nil];
[bannerTitle drawAtPoint:textPoint withAttributes:textAttributes];
}
}