Swiftpack.co - Package - pawello2222/AppIconGenerator

Language: Swift platforms

AppIconGenerator

A library for creating App Icons from SwiftUI views.

Install

AppIconGenerator is available as a Swift Package.

import AppIconGenerator

Examples

Assuming we have a SwiftUI View:

struct IconView: View { ... }

we can save it directly to a file:

AppIconGenerator().generateIcons(from: IconView())

By default it creates icons for all App Icon sizes:

static let appIconSizes = [20, 29, 40, 58, 60, 76, 80, 87, 120, 152, 167, 180, 1024]

However, you're free to modify the parameters as you wish:

AppIconGenerator().generateIcons(from: IconView(), filename = "Icon", sizes = [100, 200, 300])

Full demo:

import AppIconGenerator
import SwiftUI

struct ContentView: View {
    var body: some View {
        IconView()
            .frame(width: 100, height: 100)
            .onAppear {
                AppIconGenerator().generateIcons(from: IconView())
            }
    }
}

struct IconView: View {
    var body: some View {
        GeometryReader { geometry in
            ZStack {
                Color.blue
                Circle()
                    .fill(Color.red)
                    .frame(width: geometry.size.width / 2, height: geometry.size.height / 2)
            }
        }
    }
}

Output

Generated icons will be saved in the documents directory (the full path will be printed to the console):

File saved to: /Users/.../Library/Developer/CoreSimulator/Devices/.../Documents/Icon1024.png

License

AppIconGenerator is available under the MIT license. See the LICENSE file for more info.

Github

link
Stars: 4

Dependencies

Used By

Total: 0

Releases

0.1.0 - 2020-10-14 23:21:39