Adding an NSProgressIndicator to the dock icon

前端 未结 2 1167
無奈伤痛
無奈伤痛 2021-02-14 17:55

I\'m creating an application which should show a progress bar in the dock icon. Currently I have this, but it\'s not working:

  NSProgressIndicator *progressIndi         


        
2条回答
  •  借酒劲吻你
    2021-02-14 18:49

    In the finish I had to use the following code as the contentView was null:

        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];
    }
    

提交回复
热议问题