8 cocoa dock nsview nsprogressindicator nsdocktile
我正在创建一个应该在停靠栏图标中显示进度条的应用程序.目前我有这个,但它不起作用:
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];
Run Code Online (Sandbox Code Playgroud)
或者我必须自己在码头上画画吗?谁能帮我?谢谢.
小智 6
在完成时我必须使用以下代码,因为contentView为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];
}
Run Code Online (Sandbox Code Playgroud)
刚刚玩了一下 DockTile 示例代码:http://developer.apple.com/library/mac/#samplecode/DockTile/Introduction/Intro.html#//apple_ref/doc/uid/DTS10004391
我设法通过添加来显示 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];
Run Code Online (Sandbox Code Playgroud)
到 initWithFrame 中的 SpeedometerView.m,但它在扩展坞中仍然呈灰色。
我还找到了这个页面:http://osx.hyperjeff.net/Apps/apps?p =4&sub=22&l=1&u=on 其中有“PMProgressIndicator”可能会有所帮助,但我没有深入研究它。
希望对您有所帮助,如果您弄清楚了,请回到这里,我也有兴趣知道。