/AlternativeAppIcons

Let users choose app icons with SwiftUI on iOS 16

Primary LanguageSwiftMIT LicenseMIT

AlternativeAppIcons

Let users choose app icons with SwiftUI on iOS 16

ios-16-num-96x96_2x

Preview

CleanShot 2022-08-06 at 20 45 36

Environment

  • iOS 16
  • Xcode 14 beta 4 or above

swiftui-128x128_2x

Tutorial

Medium (https://bit.ly/3A3M5Bs)

Demo

import SwiftUI

struct ContentView: View {
    @AppStorage("appIcon") private var appIcon: String = ""
    @State var appIcons = ["AppIcon", "AppIcon 2"]
    var body: some View {
        Picker(selection: $appIcon, label: Text("App Icon Picker")) {
            ForEach(appIcons, id: \.self) { icon in
                Text(icon).tag(icon)
            }
        }.pickerStyle(.wheel)
        .onChange(of: appIcon) { newIcon in
            UIApplication.shared.setAlternateIconName(newIcon == "AppIcon" ? nil : newIcon)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

CleanShot 2022-08-06 at 21 43 56

License

MIT