2010-10-23 25 views
8

Tworzę aplikację, która powinna wyświetlać pasek postępu w ikonie dokowania. Obecnie mam to, ale to nie działa:Dodawanie NSProgressIndicator do ikony stacji dokującej

NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, 10.0f, 20.0f)]; 
    [progressIndicator setStyle:NSProgressIndicatorBarStyle]; 
    [progressIndicator setIndeterminate:NO]; 
    [[[[NSApplication sharedApplication] dockTile] contentView] addSubview:progressIndicator]; 
    [progressIndicator release]; 

Czy muszę sam narysować go na stacji dokującej? Czy ktoś może mi pomóc? Dzięki.

Odpowiedz

2

Po prostu miał bawić z przykładowego kodu DockTile: http://developer.apple.com/library/mac/#samplecode/DockTile/Introduction/Intro.html#//apple_ref/doc/uid/DTS10004391

udało mi się dostać do wyświetlania paska NSProgress tam dodając

NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, 100.0f, 20.0f)]; 
[self addSubview:progressIndicator]; 
[progressIndicator setStyle:NSProgressIndicatorBarStyle]; 
[progressIndicator setIndeterminate:NO]; 
[progressIndicator setMinValue:0]; 
[progressIndicator setMaxValue:100]; 
[progressIndicator setDoubleValue:25]; 
[progressIndicator release]; 

do SpeedometerView.m w initWithFrame, ale to wciąż było wyszarzone w doku.

Również znalazłem tę stronę: http://osx.hyperjeff.net/Apps/apps?p=4&sub=22&l=1&u=on, która ma "PMProgressIndicator", co może pomóc, ale nie zanurkowałem.

Mam nadzieję, że trochę pomogę, po powrocie tutaj, jeśli się zorientujesz, również chciałbym wiedzieć.

+0

Pomyślałem, że muszę ponownie wyświetlić pogląd docktile za każdym razem, gdy pasek postępu zmieniły. (: –

+0

Czy pasek był dla ciebie szary? Kiedy jechałem szybko, zawsze było dla mnie szaro ... – Oliver

5

W mety musiałem użyć następującego kodu jako contentView była zerowa:

docTile = [[NSApplication sharedApplication] dockTile]; 
    NSImageView *iv = [[NSImageView alloc] init]; 
    [iv setImage:[[NSApplication sharedApplication] applicationIconImage]]; 
    [docTile setContentView:iv]; 

    progressIndicator = [[NSProgressIndicator alloc] 
               initWithFrame:NSMakeRect(0.0f, 0.0f, docTile.size.width, 10.)]; 
    [progressIndicator setStyle:NSProgressIndicatorBarStyle]; 
    [progressIndicator setIndeterminate:NO]; 
    [iv addSubview:progressIndicator]; 

    [progressIndicator setBezeled:YES]; 
    [progressIndicator setMinValue:0]; 
    [progressIndicator setMaxValue:1]; 
    [progressIndicator release]; 

    [self setProgress:[NSNumber numberWithFloat:-1]]; 
} 

- (void)setProgress:(NSNumber *)fraction { 
    if ([fraction doubleValue] >= 0) { 
     [progressIndicator setDoubleValue:[fraction doubleValue]]; 
     [progressIndicator setHidden:NO]; 
    } 
    else 
     [progressIndicator setHidden:YES]; 
    [docTile display]; 
} 
Powiązane problemy