Skip to content

phosphor-icons/swift

Repository files navigation

@phosphor-icons/swift

Phosphor is a flexible icon family for interfaces, diagrams, presentations — whatever, really. Explore all our icons at phosphoricons.com.

GitHub Tag

GitHub stars GitHub forks GitHub watchers Follow on GitHub

Installation

Add this repo as a new Package Dependency with File > Add Package Dependencies... and enter this URL in the search bar:

https://github.com/phosphor-icons/swift

Choose appropriate version ranges, or use the main branch for the most recent version.

Usage

All icons are present on the Ph enum as computed properties that return a SwiftUI Image, plus some special sauce. To render an icon, use the computed weight property on the enum member, i.e. Ph.<name>.<weight>:

import SwiftUI
import PhosphorSwift

struct ContentView: View {
    var body: some View {
        HStack {
            Ph.horse.regular
                .color(.accentColor)
                .frame(width: 64, height: 64)
            Ph.heart.fill
                .color(.red)
                .frame(width: 64, height: 64)
            Ph.cube.duotone
                .frame(width: 64, height: 64)
        }   
    }
}

Note

By default, all icon images are .resizable() and rendered with .interpolation(Image.Interpolation.medium) for scalable, antialiased icons at any size, without much overhead. The frame can be sized manually, or an icon will fit the size of its parent frame – though it is recommended to use .aspectRatio(contentMode: .fit) to retain the icon's original (square) aspect ratio in this case.

Color can be applied with the .color(_: Color) modifier, which at present is simply a View extension which applies a ViewModifier to any view, causing a color mask to be applied to that view's non-transparent elements.

If weight is dynamic, you can use the .weight(_: Ph.IconWeight) method to render a weight that is not known at compile time, or to use different weights as states (e.g. active/inactive).

Our Related Projects

Community Projects

If you've made a port of Phosphor and you want to see it here, just open a PR here!

License

MIT © Phosphor Icons