About パネル
Mac アプリの多くは、メニューから「○○について」や「About ○○」をクリックすると、アプリの情報を示す「About パネル」が表示されます。
このパネルを表示するためのコードは、たった 1行です。
NSApp.orderFrontStandardAboutPanel()
使用例
Button("About this app") {
NSApp.orderFrontStandardAboutPanel()
}
標準で、アプリアイコン
、バンドル名
、バージョン情報
が表示されます。
カスタマイズ その1
orderFrontStandardAboutPanel(options:)
の引数に オプションを指定する方法です。
let textAttributes: [NSAttributedString.Key : Any] = [
.font : NSFont.systemFont(ofSize: 20.0),
.strokeColor : NSColor.cyan,
.strokeWidth : 3.0
]
let creditsText = NSAttributedString(string: "Copyright©2025", attributes: textAttributes)
let options: [NSApplication.AboutPanelOptionKey : Any] = [
.applicationVersion : "1.2.3",
.version : "abc",
.applicationName : "Test App",
.applicationIcon : NSImage(systemSymbolName: "figure", accessibilityDescription: nil)!,
.credits : creditsText,
]
NSApp.orderFrontStandardAboutPanel(options: options)
オプションの意味
- ・ ApplicationVersion
- アプリケーションバージョン(String)
指定されなければ`CFBundleShortVersionString`の値 - ・ Version
- アプリケーションのバージョン番号(String)
指定されなければ`CFBuildVersion`の値 - ・ ApplicationName
- アプリケーション名(String)
指定されなければ`CFBundleName`の値 - ・ ApplicationIcon
- アプリケーションのアイコン(NSImage)
指定されなければ、バンドルの`NSApplicationIcon`という名前の付いた画像。それもなければ、標準的なアプリケーションアイコン - ・ Credits
- 属性付き文字列(NSAttributedString)
指定されなければ、バンドルの`Credits.rtf` / `Credits.html` ファイルの内容 - ・ Copyright
- 著作権情報(String)、
指定されなければ`NSHumanReadableCopyright`の値。それもなければ空
credits
にはNSAttributedString
を指定するので、リッチテキストのように指定できます。
対して、単純な 文字列で指定する場合は、credits
の代わりにCopyright
を指定します。
let options: [NSApplication.AboutPanelOptionKey : Any] = [
.applicationVersion : "1.2.3",
.version : "abc",
.applicationName : "Test App",
.applicationIcon : NSImage(systemSymbolName: "figure", accessibilityDescription: nil)!,
.init(rawValue: "Copyright") : "Copyright©2025",
]
NSApp.orderFrontStandardAboutPanel(options: options)
.copyright
が未定義なのは、もしかしてCopyright
の使用は非推奨??
~ % swift repl
Welcome to Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4).
Type :help for assistance.
1> import AppKit
2> print(NSApplication.AboutPanelOptionKey.applicationVersion.rawValue)
ApplicationVersion
3> print(NSApplication.AboutPanelOptionKey.version.rawValue)
Version
4> print(NSApplication.AboutPanelOptionKey.applicationName.rawValue)
ApplicationName
5> print(NSApplication.AboutPanelOptionKey.applicationIcon.rawValue)
ApplicationIcon
6> print(NSApplication.AboutPanelOptionKey.credits.rawValue)
Credits
7> print(NSApplication.AboutPanelOptionKey.copyright.rawValue)
error: repl.swift:7:41:
error: type 'NSApplication.AboutPanelOptionKey' has no member 'copyright'
カスタマイズ その2
orderFrontStandardAboutPanel()
でオプションを指定せず、
プロジェクトにCredits.html
かCredits.rtf
を作成して追加する方法があります。
・ 例えば、
次の html で URLリンク
が追加されます。
Credits.html
<a style="font-family:-apple-system;"
href="https://nak435.com/">https://nak435.com/</a>
・ リッチテキストでは、
rtf ファイルの内容がそのまま追加されます。
詳しい説明は省きますが、カスタマイズその1
とその2
を組み合わせた カスタマイズも指定できます。
参考
以上