Giter Club home page Giter Club logo

colorassetcatalog's Introduction

ColorAssetCatalog

This Pod adds iOS 9+ compatibility for named colors in asset catalogs.

It extends UIColor with a new optional initializer: UIColor(asset:) that works in the same way as UIColor(named:).

This will only work in code. Named colors set in Interface Builder will still not work on iOS 9 or 10!

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS 9+
  • Xcode 9+
  • Swift 4

Installation

  1. Add pod "ColorAssetCatalog" to your Podfile
  2. Run pod install
  3. Add an Asset Catalog to your project called Colors.xcassets
  4. Add a New Copy Files Phase to your target that copies Colors.xcassets to the Resources destination (leave Subpath blank)

Notes

  • Copying Colors.xcassets to your app's Resources directory bypasses Apple's optimisations around Asset Catalogs. Think carefully whether this solution is right for you.
  • You can name your .xcassets file something else: declare ColorAssetManager.shared.catalogName = "OtherName" before using UIColor(asset:).
  • On iOS 11+, UIColor(asset:) just calls the native UIColor(named:).
  • By default, colors are lazily loaded to avoid re-parsing the asset JSON on subsequent use. Cached colors are released if the app receives a memory warning.
  • You can disable in-memory caching of colors using ColorAssetManager.shared.cachingEnabled = false.
  • Device-specific colors are supported except Watch and Mac. You can toggle them for the Color Set in the Inspector.
  • P3 (wide gamut) specific colors are supported on iOS 10+. You can toggle them for the Color Set in the Inspector.

Author

Sam Rayner, http://www.samrayner.com

License

ColorAssetCatalog is available under the MIT license. See the LICENSE file for more info.

colorassetcatalog's People

Contributors

samrayner avatar

Watchers

 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.