Subclass NSLevelIndicatorCell
and overwrite drawWithFrame:inView:
#import "CustomLevelIndicatorCell.h"
@implementation CustomLevelIndicatorCell
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
double level = (self.floatValue - self.minValue)/(self.maxValue- self.minValue);
if (level > 1.0){level = 1.0;}
NSLog(@"Level: %a", level);
NSColor *fillColor;
if(self.value < self.criticalValue)
fillColor = [NSColor redColor];
else if(self.value < self.warningValue)
fillColor = [NSColor yellowColor];
else
fillColor = [NSColor greenColor];
NSRect levelRect = NSInsetRect(cellFrame, 2, 1);
levelRect.size.width = levelRect.size.width * level;
NSBezierPath * levelPath = [NSBezierPath bezierPathWithRoundedRect:levelRect xRadius:3 yRadius:3];
[fillColor setFill];
[levelPath fill];
NSBezierPath * indicatorPath = [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(cellFrame, 2, 1) xRadius:3 yRadius:3];
[indicatorPath setLineWidth:1];
[[NSColor grayColor] setStroke];
[indicatorPath stroke];
}
@end
You can then just set the cell of your NSLevelIndicator
to your CustomLevelIndicatorCell
, either in InterfaceBuilder or in code by setCell:
Hope this helps!