簡體   English   中英

如何在iOS中獲取文件大小的本地化描述字符串?

[英]How to get localized description string of file size in iOS?

以下是我的代碼:

- (NSString *)fileSizeDescriptionForFileAtPath:(NSString *)filePath {

    NSError* error;
    NSDictionary *fileDictionary = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath
                                                                                    error: &error];
    NSNumber *size = [fileDictionary objectForKey:NSFileSize];

    NSString *desc = [NSByteCountFormatter stringFromByteCount:size.longLongValue
                                         countStyle:NSByteCountFormatterCountStyleFile];

return desc;
}

這段代碼是否可以正確格式化任何本地化的文件大小?

我在NSByteCountFormatter文檔中沒有找到有關格式化字符串已本地化的參考。

感謝您的任何建議。

因此,我嘗試了使用幾種語言環境的上述代碼,並且結果看起來完全本地化了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM