トップカテゴリーIndexCocoa
ファイルNo.157
ファイルにアイコンを付ける
画像のサムネールアイコンを付けたりしたい場合は、NSFileWrapperのsetIcon:を使います。
たとえば、「testWriteImage.tiff」というファイルにバンドル内の画像「image.tiff」をアイコンとしてセットする場合は、下記のようにします。

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{

//ファイルラッパー
NSFileWrapper *theWrapper = [[[NSFileWrapper alloc] initWithPath:[[NSBundle mainBundle]
pathForResource:@"image" ofType:@"tiff"]] autorelease];
NSImage *image = [NSImage imageNamed:@"NSApplicationIcon"];
if ([theWrapper writeToFile:@"/testWriteImage.tiff" atomically:YES updateFilenames:YES])
{
NSLog([theWrapper filename]);
[theWrapper setIcon:image];
}

}

@end
作成日:2002.11.18 更新日:2002.11.18

(c) 2002 Satoshi Oomori. All rights reserved.