Giter Club home page Giter Club logo

dynamiccolor's Introduction

DynamicColor

Supported Plateforms Version Carthage compatible Build Status codecov.io

DynamicColor provides powerful methods to manipulate colours in an easy way in Swift (iOS/OSX/WatchOS/tvOS).

example screenshot

Usage

Creation

Firstly, DynamicColor provides useful initializers to create colors using hex strings or values:

let color = UIColor(hexString: "#3498db")
// equivalent to
// color = UIColor(hex: 0x3498db)

To be platform independent, the typealias DynamicColor can also be used:

let color = DynamicColor(hex: 0x3498db)
// On iOS, WatchOS or tvOS, equivalent to
// color = UIColor(hex: 0x3498db)
// On OSX, equivalent to
// color = NSColor(hex: 0x3498db)

Darken & Lighten

These two create a new color by adjusting the lightness of the receiver. You have to use a value between 0 and 1.

lighten and darken color

let originalColor = UIColor(hexString: "#c0392b")

let lighterColor = originalColor.lighterColor()
// equivalent to
// lighterColor = originalColor.lightenColor(0.2)

let darkerColor = originalColor.darkerColor()
// equivalent to
// darkerColor = originalColor.darkenColor(0.2)

Saturate, Desaturate & Grayscale

These will adjust the saturation of the color object, much like darkenColor and lightenColor adjusted the lightness. Again, you need to use a value between 0 and 1.

saturate, desaturate and grayscale color

let originalColor = UIColor(hexString: "#c0392b")

let saturatedColor = originalColor.saturatedColor()
// equivalent to
// saturatedColor = originalColor.saturateColor(0.2)

let desaturatedColor = originalColor.desaturatedColor()
// equivalent to
// desaturatedColor = originalColor.desaturateColor(0.2)

let grayscaleColor = originalColor.grayscaledColor()

Adjust-hue & Complement

These adjust the hue value of the color in the same way like the others do. Again, it takes a value between 0 and 1 to update the value.

ajusted-hue and complement color

let originalColor = UIColor(hexString: "#c0392b")

let adjustHueColor = originalColor.adjustedHueColor(45 / 360)

let complementColor = originalColor.complementColor()

Tint & Shade

A tint is the mixture of a color with white and a shade is the mixture of a color with black. Again, it takes a value between 0 and 1 to update the value.

tint and shade color

let originalColor = UIColor(hexString: "#c0392b")

let tintColor = originalColor.tintColor()
// equivalent to
// tintColor = originalColor.tintColor(amount: 0.2)

let shadeColor = originalColor.shadeColor()
// equivalent to
// shadeColor = originalColor.shadeColor(amount: 0.2)

Invert

This can invert the color object. The red, green, and blue values are inverted, while the opacity is left alone.

invert color

let originalColor = UIColor(hexString: "#c0392b")

let invertColor = originalColor.invertColor()

Mix

This can mix a given color with the receiver. It takes the average of each of the RGB components, optionally weighted by the given percentage (value between 0 and 1).

mix color

let originalColor = UIColor(hexString: "#c0392b")

let mixColor = originalColor.mixWithColor(UIColor.blueColor())
// equivalent to
// mixColor = originalColor.mixWithColor(UIColor.blueColor(), weight: 0.5)

And many more...

DynamicColor also provides many another useful methods to manipulate the colors like hex strings, color components, etc. To go further, take a look at the example project.

Installation

CocoaPods

Install CocoaPods if not already available:

$ [sudo] gem install cocoapods
$ pod setup

Go to the directory of your Xcode project, and Create and Edit your Podfile and add DynamicColor:

$ cd /path/to/MyProject
$ touch Podfile
$ edit Podfile
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

use_frameworks!
pod 'DynamicColor', '~> 2.4.0'

Install into your project:

$ pod install

Open your project in Xcode from the .xcworkspace file (not the usual project file):

$ open MyProject.xcworkspace

You can now import DynamicColor framework into your files.

Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate DynamicColor into your Xcode project using Carthage, specify it in your Cartfile file:

github "yannickl/DynamicColor" >= 2.4.0

Swift Package Manager

You can use The Swift Package Manager to install DynamicColor by adding the proper description to your Package.swift file:

import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    targets: [],
    dependencies: [
        .Package(url: "https://github.com/yannickl/DynamicColor.git", versions: "2.4.0" ..< Version.max)
    ]
)

Note that the Swift Package Manager is still in early design and development, for more infomation checkout its GitHub Page

Manually

Download the project and copy the DynamicColor folder into your project to use it in.

Contact

Yannick Loriot

License (MIT)

Copyright (c) 2015-present - Yannick Loriot

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

dynamiccolor's People

Contributors

yannickl avatar duemunk avatar naoyashiga avatar basthomas avatar

Watchers

James Cloos avatar  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.