<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Uday Khatri on Medium]]></title>
        <description><![CDATA[Stories by Uday Khatri on Medium]]></description>
        <link>https://medium.com/@udayskhatri?source=rss-8e474e3342c6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*S0weUhl10XyZ0w9h</url>
            <title>Stories by Uday Khatri on Medium</title>
            <link>https://medium.com/@udayskhatri?source=rss-8e474e3342c6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 22:04:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@udayskhatri/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Let Users Change Your App’s Icon in iOS — Just Like X (Twitter)!]]></title>
            <link>https://medium.com/@udayskhatri/how-to-let-users-change-your-apps-icon-in-ios-just-like-x-twitter-e8141fd1f104?source=rss-8e474e3342c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8141fd1f104</guid>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[app-design]]></category>
            <dc:creator><![CDATA[Uday Khatri]]></dc:creator>
            <pubDate>Mon, 25 Mar 2024 05:14:06 GMT</pubDate>
            <atom:updated>2024-03-25T05:14:06.849Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Let Users Change Your App’s Icon in iOS — Just Like X (Twitter)!</h3><p>Have you ever noticed how some applications, like Twitter, allow users to change the app icon directly from the app settings? This subtle yet impactful feature can significantly enhance the user experience by adding a personalized touch. Today, I’m excited to share how you can implement this cool feature in your iOS applications. Whether you’re an experienced developer or a budding student in the realm of iOS development, this guide is crafted to help you add an extra layer of customization to your apps. Let’s dive in!</p><p><strong>Why Dynamic App Icons?</strong></p><p>Think beyond static app icons. Dynamic icons offer a chance to:</p><ul><li><strong>Boost User Engagement:</strong> Let users express themselves by switching icons based on mood, season, or special events.</li><li><strong>Increase Brand Awareness:</strong> Offer limited-edition icons for promotions or partnerships, keeping your app fresh in users’ minds.</li><li><strong>Enhance User Experience:</strong> Cater to user preferences, potentially improving app retention.</li></ul><p><strong>Getting Started: Prerequisites</strong></p><p>Before we dive into the code, make sure you have the following:</p><ul><li>An Xcode project with a functioning app developed with SwiftUI.</li><li>A set of icons you want to offer as user-selectable options (will require 2 sets of icons in 1040x1040 and 256 × 256 dimensions).</li></ul><p><strong>Coding the Magic: Steps to Implement Dynamic App Icons</strong></p><ol><li><strong>Prepare your app icons:</strong></li></ol><ul><li>Create a new folder under Assets within your project by pressing “+” -&gt; “Folder” (We will use this folder to store Icon images we need to show to users in the application)</li></ul><figure><img alt="How to create a new folder" src="https://cdn-images-1.medium.com/max/517/1*C7SXJ5Cm0y26uiNA7vk1kQ.png" /></figure><ul><li>Name it appropriately (e.g., “AppIcons”).</li><li>Right-click on the newly created folder and create a New iOS App Icon asset for all the icons you want to add by pressing iOS -&gt; New iOS App</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*8Mck6lnMWb7kMXgmPyWf3w.png" /></figure><ul><li>Name all the asset files meaningfully and drag and drop icons to them. remember to drag 1040x1040 ones only. It should look like this,</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ntpRz1uqimtchqYWdR79fw.png" /></figure><ul><li>Create another folder and name this one “AppIconPreview” (you can name it anything but just name it meaningfully) This folder will hold all the actual icons.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*OgrUOGqZwXL6s7ADdb7X3Q.png" /></figure><ul><li>Drag and drop all the app icons (with dimensions 256 x 256) to this folder (you can use tools like <a href="https://www.appicon.co/"><em>Ios App Icon Generator</em></a> to generate different-sized app icons as well).</li><li>After dragging and dropping all the icons, your Assets directory should look like this,</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/1*bNmCtkGOWAO20KmUkhCnxQ.png" /></figure><p>2. <strong>Writing code to change the icon:</strong></p><p>Now, for the exciting part — letting users change the icon: You can create a separate UI element (e.g., a button or a settings page) to allow users to choose their preferred icon or use any existing screen to add this option choice is completely yours. Open the swift file where you want to add the functionality to change the app icon and paste the below code before the body tag.</p><pre> private let alternateAppIcons: [String] = [<br>    &quot;AppIcon-MagnifyingGlass&quot;,<br>    &quot;AppIcon-Map&quot;,<br>    &quot;AppIcon-Mushroom&quot;,<br>    &quot;AppIcon-Camera&quot;,<br>    &quot;AppIcon-Backpack&quot;,<br>    &quot;AppIcon-Campfire&quot;<br>    ]</pre><p>This array will contain the names of all the alternate app icons we need to have when developing an app icon selection.</p><p><strong>Now let’s design the Icon selection UI</strong></p><p>You would have guessed which approach we are going to take to implement the UI by seeing the array above. Indeed we will utilize the array we just created to create a list of Items the user can select.</p><p>Paste below code:</p><pre>Section(content: {<br>                ScrollView(.horizontal, showsIndicators: false, content: {<br>                    HStack(spacing: 12) {<br>                        ForEach(alternateAppIcons.indices, id: \.self) { item in<br>                            Button(action: {<br>                                print(&quot;Icon Pressed&quot;)<br>                                UIApplication.shared.setAlternateIconName(alternateAppIcons[item]){<br>                                    error in<br>                                    if error != nil {<br>                                        print(&quot;Failed request to update the icon: \(String(describing: error?.localizedDescription))&quot;)<br>                                    } else {<br>                                        print(&quot;Success! You have changed the app icon to \(alternateAppIcons[item])&quot;)<br>                                    }<br>                                }<br>                            }, label: {<br>                                Image(&quot;\(alternateAppIcons[item])-Preview&quot;)<br>                                    .resizable()<br>                                    .scaledToFit()<br>                                    .frame(width: 80,height: 80)<br>                                    .cornerRadius(16)<br>                        })<br>                        }<br>                    }<br>                }) //: SCROLL VIEW<br>                .padding(.top,12)<br>                .listRowSeparator(.hidden)</pre><p>This code will add a horizontal list of icons and upon clicking them, the application will change its default Icon. Do notice the actual code to add the icon change functionality is achievable just by the following code. So you can be as creative as you want.</p><pre>UIApplication.shared.setAlternateIconName(alternateAppIcons[item])</pre><p>After adding the code your UI should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*varJkE_BcaV7_m--0YdLFA.png" /></figure><p>3. <strong>Work is not done yet! Additional setup required to make it work:</strong></p><p>Now at this stage, if you try to run your application and test this functionality, it won’t work and it will show an error in the console. and to resolve this error we have to perform some additional steps.</p><p>At this stage, the system doesn&#39;t know where to find the icons, we must tell the system where to find these icons in the project’s assets library.</p><ul><li>Open the navigator page and select the main project</li><li>You will find the “App icons and launch screen settings” under the “General” tab</li><li>Enable the “Include all app icon assets” option. This option will tell the project where to find the alternate app icons in the asset library.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kk1dEqKy9CgjcTz0YgS1ZA.png" /></figure><ul><li>This should be all but sometimes this option is unreliable and sometimes it doesn’t work at all. so here is the ultimate guide to solving the problem. (Keep the toggle on as it won’t harm)</li><li>Navigate to “Build Settings” from the top toolbar. and search for “app icons”. Inside Alternate App Icon Sets press “+” and type all the icon names.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tR-lT4BF2ddfrT8DdnTFdQ.png" /></figure><ul><li>Now this is all. We have successfully implemented a functionality to change the app icon directly from the app settings.</li></ul><p>4. <strong>Testing your implementation:</strong></p><p>To test, simply run your app and trigger the function you’ve written to change the icon. If everything is set up correctly, you should be able to switch between your default icon and the alternate icons you’ve provided.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*r17u5nlkdEMKdVr6uNlmIA.gif" /></figure><p>Congratulations! You’ve now added a customizable touch to your iOS app that users will love. This feature not only enhances the user experience but also shows your attention to detail and willingness to go the extra mile for your app’s personalization.</p><p>Remember, this is just one of the many ways you can make your iOS apps stand out. Keep experimenting, learning, and sharing your creations with the world. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8141fd1f104" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>