SwiftUIIcon is a library that provides scripts and preview helpers for drawing and generating your iOS, iPad OS, and macOS app icons in SwiftUI using shape and path drawing primitives.
By defining your app's icon in code, SwiftUIcon can generate all image sizes you need, show you real-time previews of your icon changes and can even allow you to integrate your icon right into your app's view hierarchy.
Icon.swift
file in your project. It must have a View
called Icon
. Check out the example for a more complex icon, but this could help get you started:struct Icon: View {
var body: some View {
IconStack { canvas in
Color.blue
}
}
}
#if DEBUG
struct Icon_Previews : PreviewProvider {
static var previews: some View {
IconPreviews(icon: Icon())
}
}
#endif
build-script.sh
included in the package. You'll need to specify the path to your Icon.swift
as the Input File (probably $(PROJECT_DIR)/$(PRODUCT_NAME)/Icon.swift
) and the Assets.xcassets
as the output file (probably $(PROJECT_DIR)/$(PRODUCT_NAME)/Assets.xcassets
):"${BUILD_ROOT%Build/*}SourcePackages/checkouts/SwiftUIcon/build-script.sh"
You can now edit the contents of the IconStack
wrapper helper view inside of Icon.swift
and add any shapes, paths or colors you want to build your icon. See Apple's SwiftUI Drawing Tutorial for more info on drawing using SwiftUI.
The IconStack
is essentially a ZStack
with a .center
alignment that provides a CanvasProxy
value to relatively position elements based on an assumed 1024x1024 canvas size. This is helpful because the Icon
is rendered individually at all the required icon sizes, so anything that has a fixed size will not scale properly. Any place where you would normally have a hard-coded number like 42
, you should instead use canvas[42]
. You can also scale fonts and other elements manually using the CanvasProxy.scale
property. As an example, Text("Testing").font(Font.system(size: 200 * canvas.scale))
should get you a properly scaled Text
element.
Slider
in your Icon too 😉MIT
link |
Stars: 99 |
Last commit: 1 year ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics