I have an Xcode project for Mac OSX, and I'd like to add an icon file (.icns) to my project and set it as the App Icon. How would I do this?
The key here is that you need an ICNS (icon set) file.
The right way to create this is described in the Human Interface Guidelines, and the details are covered in various user's guides and reference guides in Apple's maze of twisty little documentation, but I'll summarize it here.
There are third-party tools that can do this, as well as plugins for Photoshop, GIMP, Illustrator, etc., that can output a correct .icns file. But make sure, if you use such a thing, it's up to date, because Apple changes the rules all the time.
If you need to do it manually, here's what you do:
First, create a set of PNG files at different sizes. The exact list of what you need changes over time. See Provide the Correct Resources and Let OS X Do the Work if that link lasts longer than the current list; otherwise, search for it at http://developer.apple.com yourself. But, as of early 2013, it's 512x512, 256x256, 128x128, 32x32, 16x16, and #2x versions of each. All of them should have the sRGB color profile embedded in them. They should be named either icon_512x512#2x.png, icon_512x512.png, etc., or MyApp_512x512#2x.png, MyApp_512x512.png, etc. Put them all in a directory together named, e.g., MyApp.iconset.
"But wait! I just want an icon, I don't want all those sizes!" Well, you really do want all those sizes. Your 512x512 icon will look horrible when scaled down to 32x32. And on a Retina Mac, when your icon gets scaled up to double resolution, instead of getting sharper it'll just get jagged. Also, if you want to get into the App Store, Apple will reject you if you don't have them. But, if you insist, you can get away with just putting icon-512x512.png in the folder, and follow the rest of the steps, and it will work.
From the Terminal, cd into the parent directory, and type iconutil -c icns MyApp.iconset. You will get a file called MyApp.icns.
Now you can do the steps suggested by Douglas, and it will actually work. In Xcode, select your project in the Project Navigator, select your app target in the project sidebar, select the Summary tab, and drag MyApp.icns from Finder to the App Icon box.
This may not have any visible effect in the GUI, except to add MyApp.icns to the Project Navigator. In other words, you may still see the "?" icon. This seems to be a bug in Xcode 4.5. If you follow the out-of-date recommendations from the HIG two versions ago, Xcode always shows the icon, but if you follow the current HIG, it doesn't. Go figure. Hopefully Apple will fix that some day.
But for now, it doesn't matter. Build the project, and then look at MyApp.app, and it will have your icon in the Finder, on the Dock, etc.
Now, I know you don't want to draw the same picture in 10 different variations, you just want something simple. As long as you don't want to get into the App Store, you can get away with cheating, in two ways:
Scale the 512x512 (1024x1024 pixel "512x512#2x" if supporting hi res) image to all of the other sizes, using your favorite tool.
Create a .icns with nothing but the 512x512 image in the iconset.
The second one is simpler, and less cheat-y, and ultimately Finder is probably going to scale your 512x512 image as well as you would have anyway.
Finally, if you've manually edited your Info.plist or changed build settings (or you're using a project imported from a much easier version of Xcode), just dragging the image may not be enough. If you need to do the same steps manually, here they are:
MyApp.icns has to be in the Project Navigator as a file in your project. (You can drag it here from Finder.)
In Build Phases, the Copy Bundle Resources should include MyApp.icns. (You can drag it here from the Project Navigator.) (If you're not using the normal Build Phases for some reason, you need some other way to get it copied to Contents/Resources/MyApp.icns at build time.)
Your Info.plist should have an Icon file (raw name CFBundleIconFile) named MyApp, with no extension.
That's all there is to it.
In the project navigator, select an asset catalog.
Choose Editor > Add Assets > App Icons & Launch Images > New OS X Icon.
An empty OS X icon set is created, with an image well for each image representation in the set.
Drag icon file from the Finder to the appropriate image well in the set viewer.
Alternatively, you can add images by selecting an asset catalog, and choosing Editor > Add Assets > Import.
I am pretty sure you will have to put your icons into the project and then recompile. Let us know how it goes.
Related
To get custom document icons, do I need to add a new “Icon” set in Xcode’s Assets.xcassets folder by selecting Editor > Add Assets > App Icons & Launch Images > New macOS Generic Icon? Or do I just add a .icns file with appropriate sizes to the Assets.xcassets folder?
Also, I can’t find in the macOS Human Interface Guidelines what a custom document icon should look like. Most of them resemble Apple’s generic document icon with the custom file extension added at the bottom in all caps (TXT, DOCX, etc.). Do we copy Apple’s generic document icon and modify it by adding our own graphic (centered) and extension name across the bottom of it? (If so, where can that template be found?) Do we create another version of that same icon with a preview of the first page of our document (instead of the graphic)—or is that handled by the system automatically? I’ve seen both types of document icons in Finder windows.
If there is any documentation that gives a workflow for creating custom document icons for a Mac or iOS app, I would truly appreciate a reference. I’ve done an enormous amount of reading, but this is my first app. So a step-by-step answer would be most helpful.
Using Assets.xcassets does not really work that well (still with Xcode 10). I'd suggest the following steps:
Generate a ICNS file out of a PNG or TIFF file you designed for your documents, using one of the icon generator tools available in the App Store (see below on how to design a document icon).
Drag the ICNS file into your project (select copy if needed).
Switch to the target settings of your project, select the Info tab. There should be an entry in Document Types.
Select the name of the ICNS file in the drop down menu next to Icon in the document entry.
This should do it. You should see the icon in the document entry. Sometimes the Finder does not display this right away when you save a document, but maybe after a reboot.
On getting a generic document icon: If you save a document from your app without applying an icon to it first, it will show the generic icon. Do a "Get Info" from Finder, select the small icon next to the name on top of the info window and paste the TIFF into some graphic app for editing. GraphicConverter for example features New from clipboard which makes that easy.
You can also get this icon from
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericDocumentIcon.icns, but then it is in ICNS format already.
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!
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!
I did it in the most easy way:
Add "New OS X Icon" to images.xcassets and name it "DocIcon", for instance.
Drag and drop images of your document icon
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.
This is what worked for me, using Xcode 10 in 2019 (none of the other answers worked in my case):
Select asset catalog in Project Navigator
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.
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).
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...).
Copy the newly created Document.icns file as a resource to your project.
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.
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
I am trying to update an Xcode project. The update is to replace an image that is displayed in a static window. I replaced the image being called, the new image has the same name and size, but when I open the window, the image does not fill the entire window like the original image did. I a new developer in general, but a total newbie when it comes to XCode. Any help would be appreciated.
Replacing an image file in a Xcode project can be done as:
Go to File in Xcode using the Project Navigator.
Right click the file and pick "Show in Finder"
Drag new file into as same folder as the old file. (make sure the old file and the file have the same name)
Say yes, you want to replace the file.
And your done.
Compile and run will show the new image. I've done this hundreds of times, usually updating placeholder images and never had any trouble.
As for your particular problem, you didn't describe the steps you used to replace the image, so I can't testify on that, but if you do the above and don't get the results you want it's going to be from a bad image file (different size, etc).
I have been learning a lot about writing Objective-C code and designing in Interface Builder and I wanted to set icons for my simple programs.
I added the same JPG to all the size fields in Icon Composer and got an ICNS, but I couldn't figure out how to add it to the project.
Thank you in advance.
Since Xcode 4.4 Icon Composer is no longer the recommended way to create icons and is no longer included in the standard install of Xcode.
Due to the introduction of Macs with retina display, it is now recommended to provide high resolution versions of all graphics including app icons.
To give your app an icon under Xcode > 4.4 do the following:
Create a folder [IconName].iconset in Finder
In this folder place your icon as png files. You'll need the icon in
sizes of 16px, 32px, 64px (retina only), 128px, 256px, 512px and
1024px (retina only)
These icons must be named with the pattern icon_16x16.png,
icon_32x32.png, icon_128x128.png and so on
To support retina displays you must also add icon files with double
resolution, named icon_16x16#2x.png (with size 32x32),
icon_32x32#2x.png (size 64x64) and so on up to icon_512x512#2x.png (size 1024x1024).
drag this [IconName].iconset folder to Xcode (copy if necessary)
in the info.plist file set the "CFBundleIconFile" (Icon File as Key) value to
[IconName] but without the .iconset extension
Annotations:
it is (currently) not required to provide the #2x icons
it will (usually) also work if you don't provide every icon file
the iconset folder should not contain a icon_64x64.png file. the 64px icon is only for the retina version of the icon_32x32
Update:
In the end your .iconset folder has the following 10 items:
icon_16x16.png
icon_16x16#2x.png
icon_32x32.png
icon_32x32#2x.png
icon_128x128.png
icon_128x128#2x.png
icon_256x256.png
icon_256x256#2x.png
icon_512x512.png
icon_512x512#2x.png
Official guide:
https://developer.apple.com/library/content/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Optimizing/Optimizing.html
Additional information:
To convert the iconset folder to an icns file, run the following command on the terminal:
iconutil -c icns [IconName].iconset
where [IconName] should be replaced with the prefix of the iconset folder. You now have a file called [IconName].icns. In Xcode 4.4, in the Target Summary, right click the question mark for the icon, then select the icns file. You should then see the question mark get replaced with the icon.
As of Xcode 7 (not sure when this was originally introduced), you can use the Assets.xcassets file for app icons. This file is included by default for new projects.
Simply:
Go to your target's settings and ensure that under General, App Icons the Source is set to AppIcon.
Add all 10 png icons to your Assets.xcassets's AppIcon image.
Delete derived data if you have launched the app before, otherwise it will continue to show the default icon.
Run the app; it should now show your icon in the Dock, Application Switcher, and anywhere else it should appear.
Follow these steps to add an application icon to your project. This is the icon that will be show by the MacOS in the doc bar and alt-tab display.
Create an icon .icns resource file
Place it in the "resources/macos" folder
Add it to the resources group in the xcode project
Edit the Info.plist file and change the "CFBundleIconFile" value string to "icon"
Also, img2icns tool can come handy to convert images to an icon.
It's easy
Use automatic tool (Such as IconFly) for create correct ICNS or iconset with all necessary size.
Then drag and drop created ICNS or iconset to Xcode.
in the info.plist file set the "CFBundleIconFile" value to [IconName]
Steps to add an application icon to your cocoa project.
Find 'Icon Composer' from spotlight.
Drag and drop the icon(name should be like imagename.icns) in the given boxes.
Select one box and save it.
Drag and drop the saved image in the Resources folder of your application.
Select target-->right click on project name-->Select GetInfo.
In Properties enter the name of 'Icon File'.
Now Clean Build and run your application.
Xcode 8.2.1
Convert .png 👉.icns via IconMaker
Add the AwesomeApp.icns file in the same folder as info.plist
Drag AwesomeApp.icns file into xcode in the same folder as info.plist
In info.plist set icon: to AwesomeApp.icns
Step 1: Get iconfile name from info.plist and place icns(icon file) folder in SourceCode/resources folder
Step 2: And same thing goes for xcode,you have to copy all images from xcode using copyallframeworks or copyall resource file in your xcode and build the app again.
For testing the capabilities of an animation class I have created 5000 fullscreen images with 100kb size each. I added just 1000 of them to my project and Xcode is already building for 30 minutes now. The next time it would be nice if Xcode just uses the already alpha-premultiplied images from a previous build instead of stupidedly rebuilding everything. Any chance I can get that to work?
Add the build setting IPHONE_OPTIMIZE_OPTIONS=-skip-PNGs to any target that doesn't want the PNGs modified. Here's how:
Go to your projects build settings.
In the lower left hand corner is a menu you icon that looks like a GEAR
Choose Add User-Defined Setting
Name the setting: IPHONE_OPTIMIZE_OPTIONS
Set the Value to: -skip-PNGs
Do a clean build and your good to go
The idea is to do this only after you've compiled your code once. This way, the images are correctly processed once, and then you don't need XCode to do it any longer. Credits go to this site.