子类化NSLevelIndicator
并编写自己的- (void)drawRect:(NSRect)theRect
#import <Cocoa/Cocoa.h>
@interface PBLevelIndicator : NSLevelIndicator {
unsigned int mPercent;
}
@end
#import "PBLevelIndicator.h"
@implementation PBLevelIndicator
- (void)drawRect:(NSRect)theRect
{
NSRect fillingRect = theRect;
fillingRect.size.width = theRect.size.width*mPercent/100;
NSColor *indicatorColor;
if( mPercent >= 99 )
{
indicatorColor = [NSColor greenColor];
}
else if (mPercent >50)
{
indicatorColor = [NSColor yellowColor];
}
else
{
indicatorColor = [NSColor redColor];
}
[indicatorColor set];
NSRectFill(fillingRect);
}
-(void) setPercentage:(unsigned int) inPercent
{
mPercent = inPercent;
[self setNeedsDisplay:YES];
}
@end