1

I'd like to create a NSStatusItem that displays a progress spinner. My idea was to subclass NSProgressIndicator and use this as a NSView to pass to setView:.

// SpinnerView.h
//#import <Cocoa/Cocoa.h>

@interface SpinnerView : NSProgressIndicator {
    NSStatusItem *_statusItem;
    BOOL _isHighlighted;
}
- (id)initWithStatusItem:(NSStatusItem *)statusItem;
@end    

// SpinnerView.m
#import "SpinnerView.h"

@implementation SpinnerView

- (id)initWithStatusItem:(NSStatusItem *)statusItem {
    CGFloat thickness = [[NSStatusBar systemStatusBar] thickness];
    NSRect frameRect = NSMakeRect(0.0, 0.0, thickness, thickness);
    self = [super initWithFrame:frameRect];
    [self setStyle:NSProgressIndicatorSpinningStyle];
    [self setControlSize:NSSmallControlSize];
    _statusItem = statusItem;
    return self;
}

- (void)drawRect:(NSRect)dirtyRect {
    NSLog(@"drawRect");
    [_statusItem drawStatusBarBackgroundInRect:dirtyRect withHighlight:_isHighlighted];
    [super drawRect:dirtyRect];
}

@end

However, when I do this, the spinner is displayed but is surrounded by a white box:

Spinner in status bar

Any idea why this happens, or how to fix it? If I comment out the entire drawRect: method the result is the same.

augurar
  • 12,081
  • 6
  • 50
  • 65

1 Answers1

0

You need to just continually set the image for the status item. Use a timer.

uchuugaka
  • 12,679
  • 6
  • 37
  • 55