GithubHelp home page GithubHelp logo

samuel-mellert / sfsafesymbols Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sfsafesymbols/sfsafesymbols

0.0 0.0 0.0 221 KB

A type-safe way to access Apple's SF System Symbols

License: MIT License

Makefile 0.87% Swift 99.13%

sfsafesymbols's Introduction

Swift: 5.1 Version: 0.1.1 Platforms: iOS License: MIT Swift Package Manager: Compatible Accio: supported Carthage: compatible

MotivationInstallationUsageContributingLicenseIssuesPull Requests

Motivation

At WWDC 2019, Apple announced a new library of icons that come included with iOS 13. To browse them, there's even a dedicated Mac app called SF Symbols. However, developers still have to copy the name of an icon and reference it unsafely, resulting in code like this:

let image = UIImage(systemName: "circle.fill")

It didn't took long until first ideas came up to make these icons accessible in a safe way using a framework. And this is just what this framework does!

Installation

SFSafeSymbols can be installed via Swift Package Manager, Accio or Carthage:

Swift Package Manager

To integrate using Apple's Swift package manager, add the following as a dependency to your Package.swift:

.package(url: "https://github.com/piknotech/SFSafeSymbols.git", .upToNextMajor(from: "0.1"))

After specifying "SFSafeSymbols" as a dependency of the target in which you want to use it, run swift package update.

Accio

Do the same configurations as for Swift PM, then run accio update instead of swift package update.

Carthage

Make the following entry in your Cartfile:

github "piknotech/SFSafeSymbols" ~> 0.1

Then run carthage update.

Usage

All the system icons are accessible via the SFSymbol enum. They are named similar to Apple's naming, but use a lower camel case style and prefix names with leading numbers with a _ character:

c.circle        ==> SFSymbol.cCircle
e.circle.fill   ==> SFSymbol.eCircleFill
11.circle.fill  ==> SFSymbol._11CircleFill

You can now either create the corresponding UIImage by initializing it using the SFSymbol...

let image = UIImage(systemSymbol: .cCircle)
let image2 = UIImage(systemSymbol: .eCircleFill, withConfiguration: /* Some UIImage.Configuration */)
let image3 = UIImage(systemSymbol: ._11CircleFill, compatibleWith: /* Some UITraitCollection */)

... or by calling a function on your SFSymbol instance:

let image = SFSymbol.cCircle.toImage
let image2 = SFSymbol.eCircleFill.toImage(withConfiguration: /* Some UIImage.Configuration */)
let image3 = SFSymbol._11CircleFill.toImage(compatibleWith: /* Some UITraitCollection */)

... or create a SwiftUI.Image by initializing it using the SFSymbol...

Image(systemSymbol: .cCircle)

All symbols are tested so you can be sure your code won't crash because an image couldn't be found!

Contributing

Contributions are very much welcomed! See CONTRIBUTING.md for more information.

License

This library is released under the MIT License. See LICENSE.md for details.

sfsafesymbols's People

Contributors

fredpi avatar

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.