91

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.

kmikael
  • 4,962
  • 3
  • 32
  • 34

7 Answers7

166

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:

  1. Create a folder [IconName].iconset in Finder

  2. 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)

  3. These icons must be named with the pattern icon_16x16.png, icon_32x32.png, icon_128x128.png and so on

  4. 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).

  5. drag this [IconName].iconset folder to Xcode (copy if necessary)

  6. 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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
codingFriend1
  • 6,487
  • 6
  • 45
  • 67
  • In some cases the icon set won't automatically be added to the 'Copy Bundle Resources' Build Phase, in that case you need to add it to the Build Phase manually. – Reimund Mar 23 '13 at 17:20
  • +1 - The developer guide you linked in is key! It explains how to convert the folder to a .icns file, which bundles all the icons together. – jamesmortensen Apr 02 '13 at 01:22
  • 1
    Note: Xcode 4.4 automatically validates and converts an iconset folder to an icns file. All you need to do is add the iconset folder to your project and build the project. The generated icns file is added automatically to the built product. – EsbenB Apr 08 '13 at 15:01
  • An update to this from the [docs](https://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Optimizing/Optimizing.html): There is no longer a 1024x1024 size. That’s replaced by 512x512@2x. – kadam May 06 '13 at 19:25
  • 1
    @kadam You're right, that has always been the case. I slightly modified the answer to made the retina icon naming clearer. – codingFriend1 May 07 '13 at 07:09
  • Hi ... I'm getting a 'too many icons' error. When I call: iconutil -c icns iicon.iconset ... I get: ImageIO: _CGImageDestinationCreateWithWriter capacity parameter (13) is too large for this file format (max is 10) – Chris Allinson Jun 13 '13 at 15:14
  • 1
    ^ oh, they don't mention the 64x64 or 1024x1024 sizes in this documentation: https://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Optimizing/Optimizing.html ... thus this reduces the number to 10! – Chris Allinson Jun 13 '13 at 15:17
  • 1
    @ChrisAllinson You need 64px and 1024px sized icons. But these are named `icon_32x32@2x` and `icon_512x512@2x.png`. I added the listing of all icon names to the answer to clarify this. – codingFriend1 Jun 14 '13 at 07:45
  • yup, your update is correct! :D ... 10 files required, as outlined above: 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 – Chris Allinson Jun 14 '13 at 15:49
  • The name of info.plist file set is "icon file" and not "CFBundleIconFile" – Alessandro Pirovano Sep 02 '13 at 10:04
  • If using an icns file to set the icon/image of an NSStatusItem for the system tray, you must call setSize on the image or it won't show up. – Tim Beaudet Feb 24 '14 at 17:58
  • This shell script (sadly not well formatted) uses ImageMagick to convert a single icon_512x512@2x.png file into all the others needed: #!/bin/bash for size in 16 32 128 256 512; do convert 'icon_512x512@2x.png' -resize ${size}x${size} icon_${size}x${size}.png; done; for size in 16 32 128 256; do dub=$[ ${size} * 2 ]; convert 'icon_512x512@2x.png' -resize ${dub}x${dub} icon_${size}x${size}'@2x'.png; done – Tyler Apr 02 '14 at 04:07
  • As of Xcode version 10,1, or before?, the icons had to be called an '**appiconset**', not an 'iconset'. – NPAssoc Jan 30 '19 at 13:22
35

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:

  1. Go to your target's settings and ensure that under General, App Icons the Source is set to AppIcon.
  2. Add all 10 png icons to your Assets.xcassets's AppIcon image.
  3. Delete derived data if you have launched the app before, otherwise it will continue to show the default icon.
  4. Run the app; it should now show your icon in the Dock, Application Switcher, and anywhere else it should appear.
Community
  • 1
  • 1
Senseful
  • 86,719
  • 67
  • 308
  • 465
28

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.

  • …change the "CFBundleIconFile" value string to the name of your .icns file. FTFY – Francis McGrew Jun 14 '11 at 00:55
  • In Xcode 7 you don't have to place the .icns file in a specific folder, as long as it is inside the bundle. I created a folder /Assets and simply dragged the icon.icns file to the folder in Xcode. Then I edited Info.plist and set Icon file to icon.ins. You also have to disable the feature to use Assests in 'General' settings for the App. – gbdavid Jan 19 '16 at 16:38
7

It's easy

  1. Use automatic tool (Such as IconFly) for create correct ICNS or iconset with all necessary size.

  2. Then drag and drop created ICNS or iconset to Xcode.

  3. in the info.plist file set the "CFBundleIconFile" value to [IconName]

Alexandr
  • 71
  • 1
  • 1
6

Steps to add an application icon to your cocoa project.

  1. Find 'Icon Composer' from spotlight.
  2. Drag and drop the icon(name should be like imagename.icns) in the given boxes.
  3. Select one box and save it.
  4. Drag and drop the saved image in the Resources folder of your application.
  5. Select target-->right click on project name-->Select GetInfo.
  6. In Properties enter the name of 'Icon File'.
  7. Now Clean Build and run your application.
Arun
  • 69
  • 2
4

Xcode 8.2.1

  1. Convert .png .icns via IconMaker

  2. Add the AwesomeApp.icns file in the same folder as info.plist

  3. Drag AwesomeApp.icns file into xcode in the same folder as info.plist

  4. In info.plist set icon: to AwesomeApp.icns

Sentry.co
  • 5,355
  • 43
  • 38
0

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.

Rachit kapadia
  • 705
  • 7
  • 18