Subclassing NSLevelIndicatorCell
Subclassing NSLevelIndicatorCell
- Subject: Subclassing NSLevelIndicatorCell
- From: Todd Freese <email@hidden>
- Date: Thu, 28 Jun 2007 05:56:32 -0500
I am having troubles subclassing NSLevelIndicatorCell. I want to add
a text percentage display in the middle of the bar graph display.
This subclass is displayed in an NSTableView. My thoughts are to
subclass NSLevelIndicatorCell and override the drawWithFrame method.
However, my call to super does not seem to be working as my text is
displayed, but bar graph is not. Here is my code:
@implementation FSLevelIndicatorCell
- (id)init
{
self = [super init];
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (id)copy
{
return [super copy];
}
- (id)copyWithZone:(NSZone *)zone
{
id newCopy = [super copyWithZone:zone];
return newCopy;
}
- (void)drawWithFrame:(NSRect)inFrame inView:(NSView*)inView
{
// Have super draw the existing bar graph.
[super drawWithFrame:inFrame inView:inView];
// Now draw my text on top of it.
NSMutableDictionary *attrs = [NSMutableDictionary
dictionaryWithDictionary:[[self attributedStringValue]
attributesAtIndex:0 effectiveRange:NULL]];
NSRect centeredRect = inFrame;
centeredRect.size = [[self stringValue] sizeWithAttributes:attrs];
centeredRect.origin.x += ((inFrame.size.width -
centeredRect.size.width) / 2.0);
centeredRect.origin.y = ((inFrame.size.height -
centeredRect.size.height) / 2.0);
[attrs setValue:[NSColor blackColor] forKey:@"NSColor"];
[[self stringValue] drawInRect:centeredRect withAttributes:attrs];
}
_______________________________________________
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