Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/darrarski/swiftui-app-icon-creator
Create iOS and macOS application icon in Xcode with SwiftUI
https://github.com/darrarski/swiftui-app-icon-creator
app-icon app-icon-generator app-icons swift swift-ui swiftui xcode
Last synced: 23 days ago
JSON representation
Create iOS and macOS application icon in Xcode with SwiftUI
- Host: GitHub
- URL: https://github.com/darrarski/swiftui-app-icon-creator
- Owner: darrarski
- License: mit
- Created: 2020-12-13T00:23:27.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-12-22T13:20:08.000Z (almost 3 years ago)
- Last Synced: 2024-05-02T05:10:39.888Z (6 months ago)
- Topics: app-icon, app-icon-generator, app-icons, swift, swift-ui, swiftui, xcode
- Language: Swift
- Homepage: http://darrarski.pl
- Size: 998 KB
- Stars: 76
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwiftUI App Icon Creator
![Swift 5](https://img.shields.io/badge/swift-5-orange.svg)
![platform macOS 11](https://img.shields.io/badge/platform-macOS%2011-blue.svg)Create iOS and macOS application icon in Xcode with SwiftUI
*Xcode 12 and macOS 11 required*
![Creating app icon in Xcode - screenshot](screenshot_light.png)
Dark mode supported
![Creating app icon in Xcode - screenshot](screenshot_dark.png)
## 📝 How to
**TL;DR:** check out [example project](Example) in this repository.
#### 1️⃣ Create a new Swift Package
Define two products in your `Package.swift`:
- Library that will contain your icon source code
- Executable that you will use to export icon imagesAdd `swiftui-app-icon-creator` package as a dependency.
Your `Package.swift` should like this:
```swift
// swift-tools-version:5.3
import PackageDescriptionlet package = Package(
name: "my-app-icon",
platforms: [.macOS(.v11)],
products: [
.library(name: "MyAppIcon", targets: ["MyAppIcon"]),
.executable(name: "export", targets: ["Export"])
],
dependencies: [
.package(url: "https://github.com/darrarski/swiftui-app-icon-creator.git", from: "1.0.0")
],
targets: [
.target(name: "MyAppIcon", dependencies: [
.product(name: "AppIconCreator", package: "swiftui-app-icon-creator")
]),
.target(name: "Export", dependencies: ["MyAppIcon"])
]
)
```#### 2️⃣ Create an icon view in the library target, using SwiftUI
Just create a new SwiftUI view in the library target:
```swift
import SwiftUIpublic struct MyAppIconView: View {
public init() {}public var body: some View {
// ...
}
}
```#### 3️⃣ Use `IconPreviews` to live-preview your icon in Xcode
Add this code to the file which contains your icon view:
```swift
import AppIconCreatorstruct MyAppIconView_Preivews: PreviewProvider {
static var previews: some View {
IconPreviews(
icon: MyAppIconView(),
configs: .iOS
)
}
}
```Make sure you have selected the build scheme connected with your library target (`MyAppIcon` in this example).
You should be able to live-preview the icon in Xcode previews.
You can adjust the `configs` parameter to specify which types of icons you want to preview. Check out [`IconConfig.swift`](Sources/AppIconCreator/IconConfig.swift) for possible options.
#### 4️⃣ Add exporting code to the executable target
Add this code to `main.swift` file in your executable target:
```swift
import AppIconCreator
import MyAppIcon
import Foundationlet icon = MyAppIconView()
let configs = [IconConfig].iOS
let images = [IconImage].images(for: icon, with: configs)
let exportURL = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("Desktop").appendingPathComponent("MyAppIcon")
images.forEach { $0.save(to: exportURL) }
```You can adjust the `configs` variable to specify which types of icons you want to export. Check out [`IconConfig.swift`](Sources/AppIconCreator/IconConfig.swift) for possible options.
In the above example, the images will be exported to `MyAppIcon` directory on the current user's desktop. Feel free to adjust the `exportURL` variable to your needs.
#### 5️⃣ Run the executable from Xcode to export your icon images
Make sure you have selected the build scheme connected with your executable target (`export` in this example).
Images of your icon should be exported into a directory specified in `exportURL` variable.
## ☕️ Do you like the project?
## 📄 License
Copyright © 2020 Dariusz Rybicki Darrarski
License: [MIT](LICENSE)