gpt4 book ai didi

cocoa - 将 NSProgressIndicator 添加到停靠栏图标

转载 作者:行者123 更新时间:2023-12-03 16:05:25 26 4
gpt4 key购买 nike

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

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

或者我必须自己在码头上画它?谁能帮我?谢谢。

最佳答案

最后我不得不使用以下代码,因为 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];
}

关于cocoa - 将 NSProgressIndicator 添加到停靠栏图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4004941/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com