Mac:如何在坞站OSX xcode中保存备用应用程序图标 [英] Mac: How to save alternate app icon in dock OSX xcode

查看:140
本文介绍了Mac:如何在坞站OSX xcode中保存备用应用程序图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OSX应用程序的xcode中,我可以使用以下代码在扩展坞中更改应用程序图标:

In xcode on OSX app, I can change the app icon in the dock by using this code:

let image = NSImage.init(named: NSImage.Name(rawValue: "AltAppIcon"))
NSApp.applicationIconImage = image

但是当我关闭应用程序时,停靠图像会恢复为原始图标.有没有一种方法可以保存替代图标,使其即使在关闭应用程序后也始终显示?感谢您的帮助.

But when I close the application the dock image reverts back to the original icon. Is there a way I can save the alternate icon so it will show at all times even when the app is closed? Thanks for any help.

推荐答案

您可以实现Dock tile插件.不幸的是,许多与此相关的文档都消失了.您可以在

You can implement a Dock tile plug-in. Much of the documentation for this has vanished, unfortunately. You can read about loadable bundles generally and plug-ins specifically in the Code Loading Programming Topics.

您将在您的应用程序项目中创建一个新的Bundle目标. Dock tile插件的捆绑包扩展名必须是docktileplugin.您应该向该目标添加一个类,该类采用并实现 NSDockTilePlugin 协议.将捆绑软件的Info.plist中的NSPrincipalClass键设置为您的班级名称.

You would create a new Bundle target in your app project. A Dock tile plug-in's bundle extension must be docktileplugin. You should add a class to that target that adopts and implements the NSDockTilePlugin protocol. Set the NSPrincipalClass key in the bundle's Info.plist to the name of your class.

在主应用程序目标中,将要复制的捆绑软件目标的产品添加到应用程序捆绑软件中的Contents/PlugIns目录中.此外,应用程序的Info.plist需要具有键NSDockTilePlugIn,其值是插件包的名称.

In the main app target, add the bundle target's product to be copied to the Contents/PlugIns directory in your app's bundle. Also, the app's Info.plist needs to have a key NSDockTilePlugIn whose value is the name of the plugin bundle.

在加载插件时,系统将调用其-setDockTile:方法,并传入 NSDockTile 供其使用.您的代码可以使用该对象来操纵应用程序的Dock磁贴.

When your plug-in is loaded, the system will call its -setDockTile: method, passing in an instance of NSDockTile for it to use. Your code can use that object to manipulate your app's Dock tile.

这篇关于Mac:如何在坞站OSX xcode中保存备用应用程序图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆