简体   繁体   中英

How to specify different dock icon in Swift for macOS App

My app icons are a light blue with clear background and I find that it doesn't show up nicely in the macOS dock. I'm trying to find a way to use a different icon for the dock icon only but can't seem to find a way to do it programatically or through Xcode. The dock icon I created does adhere to the Apple HIG guidelines however I'm not distributing through the App Store anyways. Can anyone help me out? I'm using XCode 13 with Swift 5.

Setting NSApp.applicationIconImage should do what you need.

EDIT: If you need to display a custom icon even when the app is not running, you need to make a dock tile plugin. Unfortunately, documentation on this is pretty scarce, but basically you need to make a plugin target, embed it inside your app's bundle with the extension .docktileplugin , put the path to your plugin in your app's Info.plist under the NSDockTilePlugIn key , and then make the plugin's principal class implement the NSDockTilePlugIn protocol. Also keep in mind that dock tile plugins are not allowed in the Mac App Store, so you'll need to self-publish with a Developer ID certificate if you go this route.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM