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 [email protected]
, icon_512x512.png
, etc., or [email protected]
, 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:
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.)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.)Icon file
(raw name CFBundleIconFile
) named MyApp
, with no extension.That's all there is to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With