AlternateIcons is a Swift script that automates adding alternate app icons to your iOS app. Group your alternate icons inside an asset catalog, add a build phase and let the script set up your app. No more manual maintenance required!
You can download a pre-compiled binary for the version you want to install in the Releases section of this repository.
Once the archive is expanded, run the install.sh
script to install the script on your system.
You can build and install AlternateIcons from source using Make:
git clone https://github.com/alexaubry/alternate-icons.git
cd alternate-icons
make
make install
To set up AlternateIcons as an Xcode build phase, do the following:
-
Add your main icon to your main asset catalog.
-
Create a new Xcode asset catalog to store your icons, and do not add it to your target.
NOTE In this example, we'll name the catalog "AlternateIcons".
-
Add your alternate app icons to this asset catalog, using the 'New iOS App Icon' template.
-
In the Build Phases section of your project target, add a new Run Script phase. The script should be:
embed-alternate-icons
You now need to specify the path to the Asset Catalog you've created at step 2 under "Input Files", for example:
$(SRCROOT)/AlternateIcons.xcassets
NOTE: This Run Script phase needs to be the last build phase in your build.
-
Build your app.
Et voilà! All the icons have automatically been embedded into your app and are ready for use!
You can now change the icon from your code using:
UIApplication.shared.setAlternateIconName(iconName) { error in
// handle the result
}
Where iconName
is the name of an icon set in your alternate icons asset catalog or nil
if you want to return to the default icon.
📚 Read the documentation on developer.apple.com
A demo project is included in the Demo/
folder, to help you set up your app.
Make sure to install AlternateIcons before you build it.
Every time you build your app, the script will perform the following steps:
- Get the build products location from environment variables passed by Xcode
- Parse the Asset Catalog to build a list of icons to embed
- Copy the alternate icon files in the app bundle
- Update the
CFBundleIcon
andCFBundleIcon~ipad
sections of the Info.plist with the list of alternate icon file names
Alexis Aubry, [email protected] <@_alexaubry>
AlternateIcons uses these open source libraries:
- Files by @JohnSundell