Giter VIP home page Giter VIP logo

sfsymbols's Introduction

SFSymbols

SFSymbols gives you access to Apple's SFSymbol library in a type safe and Swifty manner. It get's difficult to remember all of the correct symbol names when using strings to label everything. This enumeration makes it easy to use a type safe interface with SFSymbols with SwiftUI, UIKit and AppKit.

Install

Add the following URL to Swift Package Manager:

https://github.com/ActuallyTaylor/SFSymbols

Basic Usage

import SwiftUI
import SFSymbols // Import SFSymbols

Image(.sparkles) // Boom ๐Ÿ’ฅ, it is that simple.

Custom Images

import SwiftUI
import SFSymbols

Image(.custom("spaceship")) // Will use a custom symbol file located in your assets folder!

Advanced Usage

SwiftUI

Images

The default Image initializer is replaced with a custom symbol initializer.

Image(.hammer)

Buttons

Two new initializers have been added to Buttons that allow you to initialize them automatically with an SFSymbol label, reducing the amount of code in your views.

// Basic Button initializer 
Button(.fireplace_fill) {
    print("Sit by the fireplace with me!")
}

// Button initializer with a role
Button(.xmark_app_fill, role: .cancel) {
    print("Goodbye!")
}

Menus

Two new initializers have been added to Menus that allow you to automatically create them with an SFSymbol image label.

// Basic menu initializer
Menu(.command) {
    Button("Hello World!") {
        print("Hello World!")
    }
}

// Menu initializer with a primary action
Menu(.command) {
    Button("Hello World!") {
        print("Hello World!")
    }
} primaryAction: {
    print("Hello World!")  
}

Labels

Labels have been given two initializers that allow you to create them with an SFSymbol.

// Just a string
Label("Hello World", symbol: .figure_wave)

// Localized string key
Label(LocalizedStringKey("hello.world"), symbol: .figure_wave)

UIKit

UIImage

UIImages have been given a set of initializers that allow you too use SFSymbols directly

UIImage(.sparkles)
UIImage(.sparkles, withConfiguration: /* some UIImage Configuration */)
UIImage(.sparkles, compatibleWith: .current)

UIButton

UIButtons have been given a system button initializer along with a way to set the image directly to an SFSymbol instead of needing to create a UIImage.

// Create a System Button with an SFSymbol
UIButton.systemButton(with: .figure_wave, target: self, action: /* any selector */)

// Set an image for a certain state
UIButton.setImage(.figure_wave, for: .normal)

DisplayRepresentation.Image

DisplayRepresentation images have been given initializers. These are only available when you are importing both UIKit and AppIntents.

DisplayRepresentation.Image(.sparkles, isTemplate: false)
DisplayRepresentation.Image(.sparkles, tintColor: .red, symbolConfiguration: /* some symbol configuration */)

UIApplicationShortcutIcon

UIApplicationShortcutIcon have been given an initializer so they can be created with an SFSymbol.

UIApplicationShortcutIcon(.sparkles)

AppKit

NSImage

NSImages have been given an initializer allowing you to create them using an SFSymbol.

NSImage(.sparkles, variableValue: 1.0)

NSButton

NSButtons have been given an initializer that allows you to initialize them with an SFSymbol. This initializer allows you to setup the button to automatically use an SFSymbol with the given variable value.

NSButton(.sparkles, variableValue: 1.0, target: self, action: /* some selector */)

sfsymbols's People

Contributors

actuallytaylor avatar mallman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

sfsymbols's Issues

License?

I want to include SFSymbols in my (as yet unreleased) iOS app, but I need your permission. ๐Ÿ‘

Can you assign a license to this project so I can give proper attribution?

Cheers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.