如何在文件的图标上显示进度条 [英] how to show a progress bar on file's icon

查看:265
本文介绍了如何在文件的图标上显示进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您知道当我们使用safari和chrome复制文件或下载文件时,文件图标上有一个微型进度条。

You know there is a mini progress bar on the file's icon when we copy a file or download file with safari and chrome.

我想知道如何让它

有人可以帮助我吗?

非常感谢。

推荐答案

我得到了查询文件/目录属性的方式。

I got the way by query file/directory attributes myself. It's quit simple.

获取要显示进度条的文件的属性

Get attributes of the file you want to show a progress bar on it's icon

NSDictionary *fileAttr = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];

获取扩展属性

NSDictionary *extendAttr = [fileAttr objectForKey:extendAttrKey];

创建extendAttr的Mutable副本并更改其中的一些值

Create a Mutable copy of extendAttr and change some value in it

NSMutableDictionary *mutableExtendAttr = [NSMutableDictionary dictionaryWithDictionary:extendAttr];
// create data of progress value
NSData *progressData = [@"0.1" dataUsingEncoding:NSASCIIStringEncoding];
// change it
[mutableExtendAttr setObject:progressData forKey:@"com.apple.progress.fractionCompleted"];

创建fileAttr的可变副本

Create a mutable copy of fileAttr

 NSMutableDictionary *mutableFileAttr = [NSMutableDictionary dictionaryWithDictionary:fileAttr];
 // change extend attr
 [mutableFileAttr setObject:[NSDictionary dictionaryWithDictionary:mutableExtendAttr] forKey:extendAttrKey];
 // change file/dir create date to the special one
 // if not , progress bar will not show
 [mutableFileAttr setObject:[NSDate dateWithString:@"1984-01-24 08:00:00 +0000"] forKey:NSFileCreationDate];
 // set attribute to file
 [[NSFileManager defaultManager] setAttributes:mutableFileAttr ofItemAtPath:filePath error:&error];

现在你会发现进度条出现了。

Now you'll find it the progress bar showed up.

这篇关于如何在文件的图标上显示进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆