我需要将NSProgressIndicator中的图像放入NSOutlineView Cell中.我已经编写了代码,为确定的指标执行此操作,它的工作效果非常好:
NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0, 0, 16, 16)];
[progressIndicator setStyle:NSProgressIndicatorSpinningStyle];
[progressIndicator setIndeterminate:NO];
[progressIndicator setMaxValue:100.0];
[progressIndicator setDoubleValue:somePercentage];
NSImage *updateImage = [[NSImage alloc] initWithData:[progressIndicator dataWithPDFInsideRect:[progressIndicator frame]]];
[progressIndicator release];
return [updateImage autorelease];
Run Code Online (Sandbox Code Playgroud)
我试图修改代码也给我不确定的指标图像.然而,对于不确定的情况,我总是得到一个空白的16x16图像.(我已经通过在每种情况下将图像写入文件来确认这一点,确定的情况给出了进度指示器图像,不确定的情况总是16x16白色方块).
修改后的代码是:
if(self.lengthUnknown)
{
NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0, 0, 16, 16)];
[progressIndicator setStyle:NSProgressIndicatorSpinningStyle];
[progressIndicator setIndeterminate:YES];
NSImage *updateImage = [[NSImage alloc] initWithData:[progressIndicator dataWithPDFInsideRect:[progressIndicator frame]]];
[progressIndicator release];
return [updateImage autorelease];
}
else
{
// Same code as the first listing, this case works fine
}
Run Code Online (Sandbox Code Playgroud)
不确定的进度指标是否使用某种类型的绘图导致-dataWithPDFInsideRect:无法捕获其图像?
更多信息:我尝试将进度指示器设置为不使用线程动画以及尝试通过NSImage的lockFocus方法获取内容,如下所示,但这些尝试都没有产生任何影响.
Dave在下面提到的进度指示器单元代码(AMIndeterminateProgressIndicatorCell)是一个很好的解决方法,但我仍然想知道为什么我不能使用与确定模式相同的技术.
我已经使用AMIndeterminateProgressIndicatorCell来获取单元格中不确定的进度指示器.这不是一个真正的NSProgressIndicator,因为它是自己的绘图,但它是一个非常好的复制品,IMO.
| 归档时间: |
|
| 查看次数: |
2262 次 |
| 最近记录: |