【问题标题】:Why is my document icon visible in properties but not on the Desktop?为什么我的文档图标在属性中可见但在桌面上不可见?
【发布时间】:2015-03-01 15:46:31
【问题描述】:

我做了一个可可应用程序,文件保存正常,当我双击一个时它会自动打开我的应用程序。我只需要弄清楚如何设置文件图标。

我为文件创建了一个 .icns 图标。这是我得到的

如您所见,文档在桌面上是“空白”,但 Finder 不知何故知道它的图标。

这是我的Info.plist

<dict>
  <key>CFBundleDevelopmentRegion</key>
  <string>en</string>
  <key>CFBundleDocumentTypes</key>
  <array>
    <dict>
      <key>CFBundleTypeIconFile</key>
      <string>FileIcon.icns</string>
      <key>CFBundleTypeName</key>
      <string>My Type</string>
      <key>CFBundleTypeRole</key>
      <string>Editor</string>
      <key>LSHandlerRank</key>
      <string>Owner</string>
      <key>LSItemContentTypes</key>
      <array>
        <string>xxx</string>
      </array>
      <key>NSDocumentClass</key>
      <string>Document</string>
    </dict>
  </array>

我试过了:

  • 上面的代码
  • 上面的代码没有.icns
  • 将新的 OSX 图标添加到 Images.xcasset 以及我用来创建 .icns 的文件

所有的结果都是一样的。有什么想法吗?

【问题讨论】:

    标签: xcode macos cocoa


    【解决方案1】:

    事实证明不需要 .icns,我用最后一个解决方案(将新的 OSX 图标添加到 Images.xcassets)再次测试,它工作正常。

    我也不知道它是否有影响,但我跑了:

    /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain user
    

    为有类似问题的人发布在 SO 上

    【讨论】:

      【解决方案2】:

      确保您的图标不包含透明度/alpha 值(如果图标是 .png 或 .tiff)。在这种情况下,请移除透明度或另存为 .jpeg。

      【讨论】:

      • 那么你如何制作具有透明度的图标呢? (例如谷歌浏览器圈)
      • 我也遇到了同样的问题,移除了图标的透明度,问题已修复...我认为这是一个新的 Apple HIG ...
      猜你喜欢
      • 1970-01-01
      • 2012-05-30
      • 2021-11-17
      • 1970-01-01
      • 2021-03-26
      • 2020-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多