How do I access images (for document icons) in an asset catalog in the Xcode 5 product preference editor

后端 未结 4 778
忘了有多久
忘了有多久 2021-02-07 06:57

I think I\'m literally on the last step before submitting a new Mac app, and I\'ve been banging my head against a wall for the past few hours on what I think should be really, r

相关标签:
4条回答
  • 2021-02-07 07:15

    To my knowledge, Xcode doesn't currently support using .xcassets for document icons. This is a little strange—the .xcassets editor clearly allows you to create new icons, but it doesn't generate .icns files, it just puts all the files in the same folder and uses a plist to manage them.

    To create an icon for your document types, upload the 1024x1024 version of the icon to http://iconverticons.com/online/ to convert it to a .icns file. Alternatively, you could use a third-party tool to generate an .icns file with different images for different resolutions. There used to be a great tool included in the Developer Tools for doing this, but I can't seem to find it anymore.

    Once you've got an icns file, add it to your project and you should be able to select it as the "Icon" for your Document Type or External/Internal UTI. Enjoy!

    To be honest, it might be worth filing a bug about this. Xcode's development seems so strongly driven by iOS these days, they may not have noticed this yet!

    0 讨论(0)
  • 2021-02-07 07:22

    Hej, allesamme,

    I had the same problem and have been researching it for days. I found a family of four solutions, the first three of which did not work for me: 1. using a .png file as the document type icon file; 2. using a manually created .icns file as the document type icon file; 3. the above solution, and 4. what I will describe here. Only the last one worked for me.

    I tried following the spirit of the above advice and found that it didn't work, at least for my MacOS app. I'm on OS X 10.9.2 (13C64) running Xcode Version 5.1 (5B130a).

    The current wisdom seems to be to create a directory in your workspace with a lower-case name and .iconset extension, in which one puts files with an icon_ prefix and the usual suffixes (16x16.png, 16x16@2x.png, 32x32.png, etc.)

    In Product Editor's Info pane you can go into Document Types and associate the .iconset file with the Icon field. The icon image happily displays something reasonable. The build process builds a .icns file from that spec and copies it into your app.

    I had an intermittent problem that the .icns file wouldn't build, which I traced to mistakenly haven included a 64x64 icon in the list. That's a no-no.

    The current Apple dogma on this issue can be found in the official documentation, which covers some details I glossed over here. I didn't need to edit the Info.plist file directly: everything seemed to work from the interfaces provided in Xcode.

    I have no idea which solutions work in which contexts, but thought I'd add throw more alternative on the fire for people to try out. — Jim Coplien

    0 讨论(0)
  • 2021-02-07 07:24

    This is what worked for me, using Xcode 10 in 2019 (none of the other answers worked in my case):

    1. Select asset catalog in Project Navigator
    2. Right click on the left pane (list of assets) and choose App Icons & Launch Images ▶︎ New macOS Generic Icon (second option from bottom). Name it "Document". This will create a folder named "Document.iconset" in the asset catalog directory.
    3. Populate all entries with your custom images. They must all be of the appropriate size (e.g., "16 x 16 @2x" must be 32 x 32 pixels, otherwise you will get yellow a warning icon over the image slot).
    4. Navigate to the asset catalog folder, and use the command: iconutil -c icns Document.iconset (must match the name of the icon created in step #2). I took this command from Apple's documentation here (which by the way, also says some BS about Xcode "automatically creating an .icns file from your .iconset folder on build". Sure...).

    5. Copy the newly created Document.icns file as a resource to your project.

    6. Select the target, open the Info pane, and in both Document Types and Exported UTIs set your .icns file as the icon for the file type.

    0 讨论(0)
  • 2021-02-07 07:34

    I did it in the most easy way:

    1. Add "New OS X Icon" to images.xcassets and name it "DocIcon", for instance.
    2. Drag and drop images of your document icon
    3. Just type "DocIcon" to icon name of your document

    You will see question mark as document icon thumbnail. Don't care about. All will work fine after build and launch of application.

    0 讨论(0)
提交回复
热议问题