Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xcode

macos

cocoa

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, really easy.

I've designed document icons for the two different types of icons my app creates and works with. I created a new "Icon" in Images.xcassets, and dropped the appropriate files into the drop zones.

In the product editor -> Info, I go to where the document type information is, but when I try to enter in the icon name in the "icon" field of either the Document Types or Exported UTI section, the icon image just turns into a question mark—no options show up in the drop down menus for icons.

How do I get the images/icons in the asset catalog to show up in the editor? Alternatively, if I was going to enter that manually into the plist, what sort of format would I use to reference an Icon file from the asset catalog?

I know I'm probably missing an easy step here, but I can't see it!

like image 558
Steven Hovater Avatar asked Nov 07 '13 20:11

Steven Hovater


People also ask

How to add image to content view Xcode?

Drag and drop image onto Xcode's assets catalog. Or, click on a plus button at the very bottom of the Assets navigator view and then select “New Image Set”. After that, drag and drop an image into the newly create Image Set, placing it at appropriate 1x, 2x or 3x slot.

How do I add images to Xcassets?

In the Project navigator, select an asset catalog: a file with a . xcassets file extension. Drag an image from the Finder to the outline view. A new image set appears in the outline view, and the image asset appears in a well in the detail area.

Where is asset catalog in Xcode?

Choose File > New > File. Choose Resource > Asset Catalog, and click Next.


2 Answers

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!

like image 91
Ben Gotow Avatar answered Oct 01 '22 11:10

Ben Gotow


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.

like image 44
Oleg Uryutin Avatar answered Oct 01 '22 11:10

Oleg Uryutin