macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

icon

INDEX>AppKit>NSAlert>

アラートウインドに表示されるアイコン画

解説

アラートウインドに表示されるアイコン画
●警告
f:id:jjj777:20150211080754p:plain

●インフォーメーション(アプリケーションのアイコン画像)
f:id:jjj777:20150211080800p:plain

古い画像をアイコンに使ったとき、「Command CodeSign failed with a nonzero exit code」というエラーが出てハマった。
リソースフォークがついているとだめらしい。
xattr -c -r "対象のファイル"
で削除して、クリーンアンドビルドでOK

When I used an old image for an icon .I got an error called "Command CodeSign failed with a nonzero exit code" and got addicted.

No fork with a resource fork.
xattr -c -r "targetImageFile"
Process with this command.

設定値

Objective-C

( NSImage * )

Swift


フレームワーク

ApplicationKit

クラス

NSAlert

使用可能

10.3-

編集時のバージョン

OS X 10.14 swift5.1

参照

-setIcon:

例文

NSLog([[alert icon] description]);

swift5.1


@IBAction func function014(sender: AnyObject) {
        
        //End even if there are other modals.
        NSApp.abortModal()
        
        //Create NSAlert
        let alert:NSAlert = NSAlert()
        
        //Set icon image
        let imageObj:NSImage = NSImage(imageLiteralResourceName: "anIcon")
        
        //Make alert icon image an imageObj
        alert.icon = imageObj
        
        //1st button
        alert.addButton(withTitle: NSLocalizedString("Stop", comment:"停止"))
        //2nd button
        alert.addButton(withTitle: NSLocalizedString("Continue", comment:""))
        //Display sheet
        alert.beginSheetModal(for: self.view.window!) { responseCode in
            if NSApplication.ModalResponse.alertSecondButtonReturn == responseCode {
                //paste  when second button is pressed
                print("SecondButton")
                //Set image to  image view on window
                self.imageView.image = imageObj
            }
        }
    }
//NSAlert icon
    
    @IBOutlet weak var imageView: NSImageView!
    @IBAction func function014(sender: AnyObject) {
        NSLog("function014 called")
        //なにかモーダルがあっても終わり
        NSApp.abortModal()
        
        //テキストの作成
        let messageText:String = "Message text" as String
        let informativeText:String = "Information text" as String
        //NSAlertの作成
        let alert:NSAlert = NSAlert()
        
        let anApplication = NSApplication.sharedApplication()
        var imageObj:NSImage = NSImage(named: "anIcon")!
        //        var imageObj:NSImage = anApplication.applicationIconImage
        alert.icon = imageObj
        //1つめのボタン
        alert.addButtonWithTitle(NSLocalizedString("Stop", comment:"停止"))
        //2つめのボタン
        alert.addButtonWithTitle(NSLocalizedString("Continue", comment:""))
        //シートを出す
        alert.beginSheetModalForWindow(window) { responseCode in
            if NSAlertSecondButtonReturn == responseCode {
                NSLog("SecondButton")
                self.imageView.image = imageObj
            }
        }
        
        
        
        
    }

f:id:jjj777:20150211220804p:plain