Swift

KubaiIcons is a Swift package that draws the icons natively in SwiftUI, each with the same motion as on the web. It uses no web view and no SVG renderer, and has no dependencies.

Install

In Xcode, choose File › Add Package Dependencies… and enter the package URL:

text
https://github.com/kubai087/kubai-icons-swift

Or add it to Package.swift:

swift
dependencies: [
    .package(url: "https://github.com/kubai087/kubai-icons-swift", from: "0.21.1"),
],
targets: [
    .target(name: "MyApp", dependencies: [
        .product(name: "KubaiIcons", package: "kubai-icons-swift"),
    ]),
]

It requires iOS 17, macOS 14, tvOS 17, watchOS 10 or visionOS 1. Versions follow the npm packages.

The icon data for all three styles is about 1.7 MB compressed. Each style's data is read the first time one of its icons is drawn.

Styles

Each style has its own view and its own list of names. The package includes these styles:

StyleViewNames
Layered (default)KubaiIconKubaiIconName
Two-toneKubaiDuotoneIconKubaiDuotoneName
LineKubaiLineIconKubaiLineName

Layered icons

Import the module and pass an icon name:

swift
import KubaiIcons

KubaiIcon(.folder)                              // plays while the pointer is over it
KubaiIcon(.folder, isActive: dropTarget)        // runs in while true, back when false
KubaiIcon(.bell, trigger: unreadCount)          // plays in and back once per change
KubaiIcon(.bookmark, isOn: saved)               // tap icons: the saved state
KubaiIcon(.folderPlus, color: .green, variant: .soft, badge: .semantic)
KubaiIcon(.folder, progress: 0.5)               // a still, halfway into its motion
ParameterDefaultDescription
size24Width and height in points. nil fills the frame you give the icon.
color.kubaiBlueThe accent color. The default is #5393FF. Every color in the icon is derived from it, as on the web.
variant.color.color or .soft, the same variants as on the web.
isOnnilThe on state of an icon that a tap toggles, such as .bookmark. Without it, a tap toggles the icon.
badge.primaryThe badge color: .primary, .semantic or .custom(Color). With .semantic, a plus or check is green, a minus or cross is red.
labelnilThe accessibility label. Without one, the icon is decorative and hidden from VoiceOver.

The drop shadow reaches a little outside the frame, so leave some room around the icon.

Layered icons are drawn by SwiftUI, like the other styles. Their motion runs each icon's own web definition in JavaScriptCore, Apple's built-in script engine, so it matches the web frame for frame: JavaScriptCore works out the shapes for each frame, and SwiftUI draws them. It is not a web view: there is no page and no separate process, and it starts the first time an icon moves. watchOS has no JavaScriptCore, so there layered icons are drawn at rest, without motion. Two-tone and line icons still move on watchOS.

Two-tone icons

swift
import KubaiIcons

KubaiDuotoneIcon(.folder)                                  // plays while the pointer is over it
KubaiDuotoneIcon(.bell, isActive: isOn)                    // runs in while true, back when false
KubaiDuotoneIcon(.bell, trigger: unreadCount)              // plays in and back once per change
KubaiDuotoneIcon(.calendarCheck, size: 32, badge: .semantic)
KubaiDuotoneIcon(.heart, color: .pink, label: "Favorite")
KubaiDuotoneIcon(.download, progress: 0.5)                 // held halfway into its motion
ParameterDefaultDescription
size24Width and height in points. nil fills the frame you give the icon.
color.kubaiPrimaryThe accent color. The default is #5A76F2.
lightcolor at 40% over whiteThe light tone of the body.
badge.primaryThe badge color: .primary, .semantic or .custom(Color). With .semantic, a plus or check is green, a minus or cross is red.
labelnilThe accessibility label. Without one, the icon is decorative and hidden from VoiceOver.

Line icons

Line icons take a stroke width and a variant, as on the web:

swift
import KubaiIcons

KubaiLineIcon(.bell)                                       // plays when the pointer arrives
KubaiLineIcon(.wifi, isActive: searching)                  // a looping motion runs while true
KubaiLineIcon(.bell, trigger: unreadCount)                 // plays once per change
KubaiLineIcon(.bell, strokeWidth: 1.5, variant: .lineDuo, color: .indigo)
KubaiLineIcon(.globe, progress: 0.3)                       // a still, 30% into its motion
ParameterDefaultDescription
size24Width and height in points. nil fills the frame you give the icon.
strokeWidth2The stroke width, any value above 0.
variant.outline.outline, .lineDuo, .fill or .solidTint: the line variants outline, line-duo, fill and solid-tint.
color.primaryThe line color. The default follows the text color.
backgroundnilThe color that the light tone and fill of .lineDuo and .solidTint mix toward. Without one, white, or black in dark mode.
badge.primaryThe badge color: .primary, .semantic or .custom(Color). With .semantic, a plus or check is green, a minus or cross is red.
labelnilThe accessibility label. Without one, the icon is decorative and hidden from VoiceOver.

Motion

A layered or two-tone icon holds its hover pose until the pointer leaves. A line motion plays once and returns to rest; looping ones, such as the Wi-Fi bars, repeat while the pointer stays and stop at the end of a cycle.

By default, an icon plays its motion while the pointer is over it, on a Mac or an iPad with a pointer. iPhone has no pointer, so start the motion from your own state:

  • isActive runs a layered or two-tone motion in while it is true and back when it turns false, for toggles and selected tabs. A line icon plays each time it turns true, and a looping one repeats until it turns false.
  • trigger plays the motion in and back once each time its value changes, for example a count of unread messages.
  • progress holds the icon still at a point in its motion, from 0 at rest to 1 fully in.

With Reduce Motion turned on, an icon jumps to each pose without animating.

Icon names

Names are the icon names on the website in camel case: alarm-clock is .alarmClock. A misspelled name fails to compile. KubaiIconName(rawValue: "alarm-clock"), KubaiDuotoneName(rawValue: "alarm-clock") and KubaiLineName(rawValue: "alarm-clock") look an icon up by its web name, and allCases lists every icon of a style, each with its category and tags.

Why not SVG files

Xcode asset catalogs and NSImage draw SVG files with Apple's built-in renderer, which renders masks at low resolution and leaves out drop shadows. Most layered and soft files use masks, as do some line and two-tone files, so in Xcode these look blurry at larger sizes.

The Swift package draws each icon from its shapes, so it stays sharp at every size and keeps its motion.

Why not a web view

The web packages also work inside a WKWebView, but a web view runs a full browser engine in its own process and loads a page before the icon appears. That is a lot for an icon, and slow in lists. The Swift package draws the same icons with the same motion natively. Use the web packages only where the screen is already a web page, as in a hybrid app.

UIKit and AppKit

The icons are SwiftUI views. In UIKit, put one in a UIHostingController; in AppKit, in an NSHostingView:

swift
import KubaiIcons
import SwiftUI

// UIKit, in a view controller
let host = UIHostingController(rootView: KubaiIcon(.folder, label: "Folder"))
host.sizingOptions = .intrinsicContentSize
host.view.backgroundColor = .clear
addChild(host)
view.addSubview(host.view)
host.didMove(toParent: self)

// AppKit
let icon = NSHostingView(rootView: KubaiIcon(.folder, label: "Folder"))

To start the motion from UIKit code, keep the value you pass to isActive or trigger in an @Observable model that the view reads.

Updating

New icons come out in new releases. To update, choose File › Packages › Update to Latest Package Versions in Xcode.

The package is published from packages/swift in the main repository on each release. Report issues there.