将 NSProgressIndicator 添加到停靠栏图标

发布于 2024-09-28 21:38:42 字数 461 浏览 3 评论 0 原文

我正在创建一个应用程序,它应该在停靠图标中显示进度条。目前我有这个,但它不起作用:

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

或者我必须自己在码头上画它?有人可以帮助我吗?谢谢。

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

Or must I draw it on the dock myself? Can anyone help me? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抽个烟儿 2024-10-05 21:38:42

最后我不得不使用以下代码,因为 contentView 为空:

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

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];
}
做个少女永远怀春 2024-10-05 21:38:42

刚刚玩了一下 DockTile 示例代码: http://developer.apple.com/library/mac/#samplecode/DockTile/Introduction/Intro.html#//apple_ref/doc/uid/DTS10004391

我设法得到了通过在 initWithFrame 中添加到 SpeedometerView.m 来显示 NSProgress 栏

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

,但它在扩展坞中仍然呈灰色。

我还找到了此页面: http:// /osx.hyperjeff.net/Apps/apps?p=4&sub=22&l=1&u=on 其中有“PMProgressIndicator”可能会有所帮助,但我没有深入研究它。

希望对您有所帮助,如果您弄清楚了,请回到这里,我也有兴趣知道。

Just had a play around with the DockTile sample code: http://developer.apple.com/library/mac/#samplecode/DockTile/Introduction/Intro.html#//apple_ref/doc/uid/DTS10004391

I managed to get an NSProgress bar to display there by adding

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

to SpeedometerView.m in initWithFrame, but it was still greyed out in the dock.

I also found this page: http://osx.hyperjeff.net/Apps/apps?p=4&sub=22&l=1&u=on which has "PMProgressIndicator" which might help, but I didn't dive through it.

Hope that helps a bit, post back on here if you figure it out, I'd be interested to know as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文