set app icon

Sep 05, 2021 appicon

How to set App Icon Xcode Dynamically

How To Dynamically Change Your  App Icon in iOS Application

Today We are going to Start the Dynamic set App Icon Xcode in iOS Application. to get Started we need a couple of AppIcon. they should be placed on group rather that asset catalog.

basically we needed to use the @1x , @2x and @3x size for the App icon in iOS Application.

For Example we are using

alternative app icons

[email protected],[email protected],[email protected]

[email protected],[email protected],[email protected]

[email protected],[email protected],[email protected]

The Icon Which We are using should be of PNG format

Lets Start How to Add this App Icon  in the Xcode.

Step1.  Open the Project navigation .Right click on Plist file and Open it as “Open As SourceCode”. Which will Show the Raw file of XML of the plist file .

</dict>

</plist>




At the End of the Plist we will get the above Code

<key>CFBundleIcons</key>

<dict>

    <key>CFBundlePrimaryIcon</key>

    <dict>

        <key>CFBundleIconFiles</key>

        <array>

            <string>Icon-1</string>

        </array>

        <key>UIPrerenderedIcon</key>

        <false/>

    </dict>

    <key>CFBundleAlternateIcons</key>

    <dict>

        <key>iOSAppIcon-2</key>

        <dict>

            <key>CFBundleIconFiles</key>

            <array>

                <string>Icon-2</string>

            </array>

            <key>UIPrerenderedIcon</key>

            <false/>

        </dict>

        <key>iOSAppIcon-3</key>

        <dict>

            <key>CFBundleIconFiles</key>

            <array>

                <string>Icon-3</string>

            </array>

            <key>UIPrerenderedIcon</key>

            <false/>

        </dict>

    </dict>

</dict>

Add the Following Code in the Plist File before </plist>

 

Here defining the App Icon is specific in the property List keys

CFBundleIcons is the Dictionary that Define the Primary icon CFBundlePrimaryIcon

The iOSAppIcon-2 and iOSAppIcon-3 are just the reference given .

Whenever We wanted to change the App we needed to call the setAlternateIconName() as shown in below Code

 UIApplication.shared.setAlternateIconName("AppIcon-2")

    To reset your icon to the primary icon, you would use this:

    UIApplication.shared.setAlternateIconName(nil)

We can check whether your app is able to switch to an alternate icon by using the supportAlternateIcons on the application

 if UIApplication.shared.supportsAlternateIcons {

        // let the user choose a new icon

    }

iOS App icon generator

Index