Skip to content

Instantly share code, notes, and snippets.

@1998code
Created August 6, 2022 13:09
Show Gist options
  • Save 1998code/134586a51071e8e370d8a36660bcb753 to your computer and use it in GitHub Desktop.
Save 1998code/134586a51071e8e370d8a36660bcb753 to your computer and use it in GitHub Desktop.
Pick an app icon
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()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment