iconForFileType:
拡張子・HFSファイルタイプでファイルのアイコンを返します
- (NSImage *)iconForFileType:(NSString *)fileType
func iconForFileType(_ fileType: String) -> NSImage
解説
拡張子・HFSファイルタイプでファイルのアイコンを返します。
フレームワーク
ApplicationKit
クラス
NSWorkspace
使用可能
10.0
参照
- iconForFile:
- iconForFiles:
更新時のバージョン
OS X 10.10.3
Swift1.2
例文
theImage = [[NSWorkspace sharedWorkspace] iconForFileType:[path pathExtension]]; /// [image setImage:[[NSWorkspace sharedWorkspace] iconForFileType:@"tiff"]];
//NSWorkspace iconForFile @IBAction func function030(sender: AnyObject) { var aWindow : NSWindow = NSWindow(contentRect: NSMakeRect(0.0, 0.0, 300, 200), styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask, backing: .Buffered, defer: false , screen: NSScreen.mainScreen()) windowArray.addObject(aWindow) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄 //ファイルを選択 var openPanel = NSOpenPanel() openPanel.allowsMultipleSelection = false openPanel.canChooseDirectories = false openPanel.canCreateDirectories = false openPanel.canChooseFiles = true openPanel.beginWithCompletionHandler { (result) -> Void in //オープンパネルでOKを選択したら if result == NSFileHandlingPanelOKButton { //選択したファイルを let theWorkspace : NSWorkspace = NSWorkspace.sharedWorkspace() let theURL : NSURL = openPanel.URL! let filepath : NSString = theURL.path! var theView : NSImageView = NSImageView(frame: NSMakeRect(0.0, 0.0, 100.0, 100.0)) theView.image = theWorkspace.iconForFile(filepath as String) aWindow.contentView.addSubview(theView) aWindow.center()//ウインドウをスクリーンの中心に aWindow.orderFront(self)//前面に aWindow.makeKeyAndOrderFront(self)//表示 }//if result }//openPanel.beginWithCompletionHandler }