Re: Subclassing NSLevelIndicatorCell
Re: Subclassing NSLevelIndicatorCell
- Subject: Re: Subclassing NSLevelIndicatorCell
- From: Todd Freese <email@hidden>
- Date: Thu, 28 Jun 2007 10:13:35 -0500
My issue turned out to be an incorrect style setting on the cell.
However, I have been able to subclass NSLevelIndicatorCell just fine.
I override drawWithFrame and it is working fine under Tiger. Of
course, I have only tried using the cell in a TableView. Here is my
final code.
@implementation FSLevelIndicatorCell
- (void)drawWithFrame:(NSRect)inFrame inView:(NSView*)inView
{
// Have super draw bar graph.
[super drawWithFrame:inFrame inView:inView];
// Add custom text percentage on top.
int percentage = [self floatValue] * 100;
NSString *percentageString = [NSString stringWithFormat:@"%d%%",
percentage];
NSMutableDictionary *attrs = [NSMutableDictionary
dictionaryWithDictionary:[[self attributedStringValue]
attributesAtIndex:0 effectiveRange:NULL]];
NSRect centeredRect = inFrame;
centeredRect.size = [percentageString 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"];
[percentageString drawInRect:centeredRect withAttributes:attrs];
}
@end
Todd
.
On Jun 28, 2007, at 8:37 AM, Adam R. Maxwell wrote:
On Jun 28, 2007, at 03:56, Todd Freese wrote:
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:
NSLevelIndicatorCell doesn't call the NSCell drawing methods
AFAICT, so subclassing it is impossible (rdar://problem/4998206).
You can override one of its private drawing methods such as
_drawRelevancyWithFrame:inView:, but that may break if and when
they fix it. I did it because the default height in a tableview is
ugly, so if it breaks it's not critical.
--
Adam
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/
email_________________________________________________________________
_____
_______________________________________________
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