GithubHelp home page GithubHelp logo

giulio92 / glcolor Goto Github PK

View Code? Open in Web Editor NEW
3.0 0.0 1.0 24 KB

UIColor subclass/extension for device gamut-aware colors

License: MIT License

Swift 57.85% Ruby 42.15%
ios uicolor swift srbg p3 colors

glcolor's Introduction

GLColor

Language Supported platforms CocoaPods codebeat badge license

๐Ÿ“„ What it is

GLColor is a drop-in, ready to use, UIColor subclass and extension that can be used to generate device gamut-aware (sRGB or DCI-P3) UIColors or convert existing ones automatically.

As Apple Human Interface Guidelines reports its important to use wide color on compatible displays whenever possible to ensure the best color experience in your applications. Unfortunately the regular UIColor uses sRGB as the default color space, causing DCI-P3 compatible to render in sRBG mode all the time, instead of being able to show all the possible colors. To enable DCI-P3 rendering you must initialize a UIColor using a new alternative init signature provided by Apple:

UIColor(displayP3Red:, green:, blue:, alpha:)

But this can lead to repetitive error-prone code and/or if statements since you always have to specify which color gamut to use for every single UIColor in your code, based on device capabilities.

๐Ÿ›  How to use

With GLColor you have two simple choices:

  1. Use it like a UIColor replacement to initialize a gamut-aware color with the provided signature:
    init(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat, gamut: UIDisplayGamut)
    
  2. Use the provided extension with your already existing UIColors:
    let color: UIColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
    color.matching(colorGamut: traitCollection.displayGamut)
    

Where the gamut and colorGamut parameters are your UITraitCollection .displayGamut value used to determine the correct color space to use. The sRBG to DCI-P3 color space convertion will occur only on compatible devices.

๐Ÿ”ฐ Installation

CocoaPods

  1. Add the following entry in your Podfile:
    pod 'GLColor'
    
  2. Run pod install

Manual installation

  1. Download the latest version
  2. Copy the GLColor.swift file in your Xcode project structure

Devices supporting DCI-P3 color space:

๐Ÿ“ฑ iOS:

  • iPhone X
  • iPhone 8/8 Plus
  • iPhone 7/7 Plus
  • iPad Pro 12.9-inch (2nd generation)
  • iPad Pro 10.5-inch
  • iPad Pro (9.7-inch)

๐Ÿ–ฅ macOS:

  • iMac Retina 5K Late 2015+
  • iMac Retina 4K Late 2015+
  • iMac Pro Late 2017+
  • MacBook Pro 2016+

๐Ÿ“บ tvOS:

  • Apple TV 4th gen+

๐Ÿ“š Further readings

glcolor's People

Contributors

alex-taffe avatar giulio92 avatar

Stargazers

 avatar  avatar  avatar

Forkers

alex-taffe

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.