A beautiful set of predefined colors and a set of color methods to make your iOS/OSX development life easier.

Overview

ScreenShot

Build Status

Gitter chat

Installation

Drag the included Colours.h and Colours.m files into your project. They are located in the top-level directory. You can see a demo of how to use these with the included Xcode project as well.

#import "Colours.h" into the classes you want to use this category in and you're all set.

CocoaPods

pod 'Colours'

or, for Swift:

pod 'Colours/Swift'

NSColor

Colours supports NSColor out of the box! Just make sure you have the AppKit framework installed (it comes that way for a new application) and you will be set. This README uses UIColor for its examples, just substitute NSColor and the methods are all the same.

Swift

A Swift version of Colours now exists that contains everything in the Obj-C version except:

  • Color Components Dictionary (use the tuples instead)
  • Sorting/Comparing Colors
  • Distance between Colors

Also, instead of dictionaries and arrays of color components, tuples are used instead. So instead of [someRedColor rgbaArray], you would use someRedColor.rgba() which gives you a tuple of four CGFloats like (1.0, 0.0, 0.0, 1.0). To get just the red value, you would write someRedColor.rgba().r.

Table of Contents

Color Palette

infoBlueColor infoBlueColor successColor successColor warningColor warningColor
dangerColor dangerColor antiqueWhiteColor antiqueWhiteColor oldLaceColor oldLaceColor
ivoryColor ivoryColor seashellColor seashellColor ghostWhiteColor ghostWhiteColor
snowColor snowColor linenColor linenColor black25PercentColor black25PercentColor
black50PercentColor black50PercentColor black75PercentColor black75PercentColor warmGrayColor warmGrayColor
coolGrayColor coolGrayColor charcoalColor charcoalColor tealColor tealColor
steelBlueColor steelBlueColor robinEggColor robinEggColor pastelBlueColor pastelBlueColor
turquoiseColor turquoiseColor skyBlueColor skyBlueColor indigoColor indigoColor
denimColor denimColor blueberryColor blueberryColor cornflowerColor cornflowerColor
babyBlueColor babyBlueColor midnightBlueColor midnightBlueColor fadedBlueColor fadedBlueColor
icebergColor icebergColor waveColor waveColor emeraldColor emeraldColor
grassColor grassColor pastelGreenColor pastelGreenColor seafoamColor seafoamColor
paleGreenColor paleGreenColor cactusGreenColor cactusGreenColor chartreuseColor chartreuseColor
hollyGreenColor hollyGreenColor oliveColor oliveColor oliveDrabColor oliveDrabColor
moneyGreenColor moneyGreenColor honeydewColor honeydewColor limeColor limeColor
cardTableColor cardTableColor salmonColor salmonColor brickRedColor brickRedColor
easterPinkColor easterPinkColor grapefruitColor grapefruitColor pinkColor pinkColor
indianRedColor indianRedColor strawberryColor strawberryColor coralColor coralColor
maroonColor maroonColor watermelonColor watermelonColor tomatoColor tomatoColor
pinkLipstickColor pinkLipstickColor paleRoseColor paleRoseColor crimsonColor crimsonColor
eggplantColor eggplantColor pastelPurpleColor pastelPurpleColor palePurpleColor palePurpleColor
coolPurpleColor coolPurpleColor violetColor violetColor plumColor plumColor
lavenderColor lavenderColor raspberryColor raspberryColor fuschiaColor fuschiaColor
grapeColor grapeColor periwinkleColor periwinkleColor orchidColor orchidColor
goldenrodColor goldenrodColor yellowGreenColor yellowGreenColor bananaColor bananaColor
mustardColor mustardColor buttermilkColor buttermilkColor goldColor goldColor
creamColor creamColor lightCreamColor lightCreamColor wheatColor wheatColor
beigeColor beigeColor peachColor peachColor burntOrangeColor burntOrangeColor
pastelOrangeColor pastelOrangeColor cantaloupeColor cantaloupeColor carrotColor carrotColor
mandarinColor mandarinColor chiliPowderColor chiliPowderColor burntSiennaColor burntSiennaColor
chocolateColor chocolateColor coffeeColor coffeeColor cinnamonColor cinnamonColor
almondColor almondColor eggshellColor eggshellColor sandColor sandColor
mudColor mudColor siennaColor siennaColor dustColor dustColor

Using Predefined Colors

Colours was set up to be exactly like using an Apple predefined system color. For instance, to get a stark red, you type [UIColor redColor]. You don't get a lot of variation on this though without diving into the colorWithRed:green:blue:alpha: method and customizing the heck out of it. Well, I took the liberty of creating 100 colors to use in the same system color way that Apple uses with iOS. So instead of the redColor example earlier, just substitute one of the colors from the giant palette above, like so: [UIColor indigoColor].

Color Helper Methods

Beyond giving you a list of a ton of colors with no effort, this category also gives you some methods that allow different color manipulations and translations. Here's how you use these:

Hex String

You can convert the commonly seen hexadecimal color string (ahh, thank you CSS) to a UIColor, and vice versa, very easily using the following methods:

UIColor *newColor = [UIColor colorFromHexString:@"#f587e4"];
NSString *hexString = [newColor hexString];

RGBA

RGBA Array to and from a UIColor

The color -> array method creates an array of 4 NSNumbers representing the RGBA values of the color. These are not in the 0-255 range, but rather normalized in the 0-1 range. So if your R is 230, then it will be represented in the array as 0.902.

NSArray *colorArray = [[UIColor seafoamColor] rgbaArray];
UIColor *newColor = [UIColor colorFromRGBAArray:colorArray];

RGBA Dictionary to and from a UIColor

Similar to the array method above, this returns an NSDictionary that contains NSNumbers. Static keys are used to access the different color components of the dictionary. This allows you to use autocorrect to use the returned dictionary faster.

  • kColoursRGBA_R
  • kColoursRGBA_G
  • kColoursRGBA_B
  • kColoursRGBA_A
NSDictionary *colorDict = [[UIColor seafoamColor] rgbaDictionary];
UIColor *newColor = [UIColor colorFromRGBADictionary:colorDict];

// You can also get a single component like so:
NSNumber *r = colorDict[kColoursRGBA_R];

HSBA

Like both of the RGBA methods above, you can also get the Hue, Saturation and Brightness values from a UIColor and create an array or dictionary out of them, or vice versa. The colorDictionary returned also uses static keys like the RGBA version of this method. Here are the ones to use:

  • kColoursHSBA_H
  • kColoursHSBA_S
  • kColoursHSBA_B
  • kColoursHSBA_A
NSArray *colorArray = [[UIColor seafoamColor] hsbaArray];
NSDictionary *colorDict = [[UIColor seafoamColor] hsbaDictionary];

UIColor *newColor1 = [UIColor colorFromHSBAArray:colorArray];
UIColor *newColor2 = [UIColor colorFromHSBADictionary:colorDictionary];

CIELAB

Like both of the RGBA methods above, you can also get the CIE_Lightness, CIE_a and CIE_b values from a UIColor and create an array or dictionary out of them, or vice versa. The colorDictionary returned also uses static keys like the RGBA version of this method. Here are the ones to use:

  • kColoursCIE_L
  • kColoursCIE_A
  • kColoursCIE_B
  • kColoursCIE_alpha
NSArray *colorArray = [[UIColor seafoamColor] CIE_LabArray];
NSDictionary *colorDict = [[UIColor seafoamColor] CIE_LabDictionary];

UIColor *newColor1 = [UIColor colorFromCIE_LabArray:colorArray];
UIColor *newColor2 = [UIColor colorFromCIE_LabDictionary:colorDictionary];

CMYK

Like both of the RGBA methods above, you can also get the CMYKY values from a UIColor and create an array or dictionary out of them, or vice versa. The colorDictionary returned also uses static keys like the RGBA version of this method. Here are the ones to use:

  • kColoursCMYK_C
  • kColoursCMYK_M
  • kColoursCMYK_Y
  • kColoursCMYK_K
NSArray *colorArray = [[UIColor seafoamColor] cmykArray];
NSDictionary *colorDict = [[UIColor seafoamColor] cmykDictionary];

UIColor *newColor1 = [UIColor colorFromCMYKArray:colorArray];
UIColor *newColor2 = [UIColor colorFromCMYKDictionary:colorDictionary];

Color Components

This method returns a dictionary containing values for each of the keys (RGBA, HSBA, CIE_LAB, CMYK) from above. This means you can get a hue value and a Lightness value from the same source. Here's how you use this:

NSDictionary *components = [someColor colorComponents];
CGFloat H = components[kColoursHSBA_H];
CGFloat L = components[kColoursCIE_L];

You can also retrieve singular values instead of the entire dictionary by calling any of these methods below on a UIColor. This will be significantly slower at getting all of the values for one color, versus just retrieving one. If you need more than one, call the specific array or dictionary method from above.

CGFloat R = [[UIColor tomatoColor] red];
CGFloat G = [[UIColor tomatoColor] green];
CGFloat B = [[UIColor tomatoColor] blue];
CGFloat H = [[UIColor tomatoColor] hue];
CGFloat S = [[UIColor tomatoColor] saturation];
CGFloat B = [[UIColor tomatoColor] brightness];
CGFloat CIE_L = [[UIColor tomatoColor] CIE_Lightness];
CGFloat CIE_A = [[UIColor tomatoColor] CIE_a];
CGFloat CIE_B = [[UIColor tomatoColor] CIE_b];
CGFloat alpha = [[UIColor tomatoColor] alpha];

Darken/Lighten Colors

You can darken or lighten a color by using these methods. The only parameter is a percentage float from 0 -> 1, so a 25% lighter color would use the parameter 0.25.

UIColor *lighterColor = [[UIColor seafoamColor] lighten:0.25f];
UIColor *darkerColor = [[UIColor seafoamColor] darken:0.25f];

Black or White Contrasting Color

A lot of times you may want to put text on top of a view that is a certain color, and you want to be sure that it will look good on top of it. With this method you will return either white or black, depending on the how well each of them contrast on top of it. Here's how you use this:

UIColor *contrastingColor = [[UIColor seafoamColor] blackOrWhiteContrastingColor];

Complementary Color

This method will create a UIColor instance that is the exact opposite color from another UIColor on the color wheel. The same saturation and brightness are preserved, just the hue is changed.

UIColor *complementary = [[UIColor seafoamColor] complementaryColor];

Distance between 2 Colors

5.1.0 +

Detecting a difference in two colors is not as trivial as it sounds. One's first instinct is to go for a difference in RGB values, leaving you with a sum of the differences of each point. It looks great! Until you actually start comparing colors. Why do these two reds have a different distance than these two blues in real life vs computationally? Human visual perception is next in the line of things between a color and your brain. Some colors are just perceived to have larger variants inside of their respective areas than others, so we need a way to model this human variable to colors. Enter CIELAB. This color formulation is supposed to be this model. So now we need to standardize a unit of distance between any two colors that works independent of how humans visually perceive that distance. Enter CIE76,94,2000. These are methods that use user-tested data and other mathematically and statistically significant correlations to output this info. You can read the wiki articles below to get a better understanding historically of how we moved to newer and better color distance formulas, and what their respective pros/cons are.

Finding Distance

CGFloat distance = [someColor distanceFromColor:someOtherColor type:ColorDistanceCIE94];
BOOL isNoticablySimilar = distance < threshold;

References

Generating Color Schemes

You can create a 5-color scheme based off of a UIColor using the following method. It takes in a UIColor and one of the ColorSchemeTypes defined in Colours. It returns an NSArray of 4 new UIColor objects to create a pretty nice color scheme that complements the root color you passed in.

NSArray *colorScheme = [color colorSchemeOfType:ColorSchemeType];

ColorSchemeTypes

  • ColorSchemeAnalagous
  • ColorSchemeMonochromatic
  • ColorSchemeTriad
  • ColorSchemeComplementary

Here are the different examples starting with a color scheme based off of [UIColor seafoamColor].

ColorSchemeAnalagous

Analagous

ColorSchemeMonochromatic

Monochromatic

ColorSchemeTriad

Triad

ColorSchemeComplementary

Complementary

Android

My friend, Matt York ported a version of this repository over to Android, so you can use these exact same colors and color methods in your Android apps as well. You can find it here: Colours for Android.

Xamarin

akamud has graciously ported this library as a Xamarin Android component, which can be found at https://github.com/akamud/Colours. An iOS Xamarin component is in the works as well.

Reap What I Sow!

This project is distributed under the standard MIT License. Please use this and twist it in whatever fashion you wish - and recommend any cool changes to help the code.

Bitdeli Badge

Comments
  • Odd behavior with darken/lighten

    Odd behavior with darken/lighten

    Hi,

    I think there is either a bug with darken or I'm misunderstanding how to use it. Given an existing UIColor, if I lighten it by 0.15f, it lightens correctly (albeit slightly more than I might expect, but other color libraries, such as the one in less.js, behave identically). However, darkening by any amount results in a color that is not exactly black, but essentially black. What's odd is that lightening by a negative float gives exactly the results I'd expect.

    searchInput.backgroundColor = [[Colors teal] lighten:-0.15f]; // perfect
    searchInput.backgroundColor = [[Colors teal] darken:0.15f]; // black
    
    

    screen shot 2015-01-15 at 5 48 07 pm screen shot 2015-01-15 at 5 48 26 pm

    opened by jimbojsb 5
  • Publish to CocoaPods

    Publish to CocoaPods

    It's only one class, but adding to CocoaPods will be great for CocoaPods users because:

    • They can get this just like their other libs
    • They can get updates when available.
    opened by jasperblues 5
  • RGBA <-> HSBA color conversion issue

    RGBA <-> HSBA color conversion issue

    Hello,

    I was trying to debug the darken/lighten functions while it used to work properly, it does not seem to any more. I've looked into this some more and found if you try to convert colors between 2 color spaces, they are not equivalent. For instance, try this:

    NSArray *hsbColorArray = [[UIColor blueColor] hsbaArray]; ===> Yields a blue color UIColor *color = [UIColor colorFromHSBAArray:hsbColorArray]; ===> Yields a red color

    Thanks.

    opened by winstonyang 3
  • New method to get colour given distance and variable parameter

    New method to get colour given distance and variable parameter

    I'm working on a project that needs a fair bit of colour work, and thought I'd take a stab at contributing here as your project already has some of what I'll need (LAB support).

    I'm looking to add some methods which produce a derivative colour with a set perceptual distance, based on altering some parameter of the original colour. For example, say you want a highlight colour that's just noticeable on top of a given background colour, regardless what the background is. Maybe it'd look something like this:

    let highlight = base.colourWithDistance(5, variable: .CIE_L, direction: .Up, type: .CIE76)
    

    I thought I knew how to do it (rearrange the various formulas in the distanceFromColor:colortype:distanceType methods and solve for variable), but I'm stuck on the basic LAB manipulation. Does anyone have an idea why in the following code, when I change L, A and B also change? Am I misunderstanding how the LAB model works? Are L, A and B not independent?

    let firstColour = ...
    
    let dictionary1 = firstColour.CIE_LabDictionary() as [NSString:NSNumber]
    println(dictionary1)
    
    dictionary1[kColoursCIE_L] = 60
    
    let secondColour = UIColor(fromCIE_LabDictionary: dictionary1)
    dictionary2 = secondColour.CIE_LabDictionary() as [NSString:NSNumber]
    println(dictionary2)
    
    
    // Gives:
    // [LABa-A: -57.8215, LABa-L: 91.2403, LABa-B: 87.4349, LABa-a: 1]
    // [LABa-A: -54.8815, LABa-L: 60.2418, LABa-B: 61.5021, LABa-a: 1]
    

    Thanks for any input!

    opened by danhalliday 3
  • EXC_BAD_ACCESS with NULL Pointer

    EXC_BAD_ACCESS with NULL Pointer

    I've got a simple MKMapView and when I present an UIAlertView I get an EXC_BAD_ACCESS.

    The swizzled method - (BOOL)colours_getHue:(CGFloat *)hue saturation:(CGFloat *)saturation brightness:(CGFloat *)brightness alpha:(CGFloat *)alpha; is called by the MapKit framework with an alpha pointer that is NULL. This leads to writing an alpha value to the address 0x00000000 .

    I fixed it by testing the alpha pointer for NULL prior to setting its value:

    if (alpha) {
        *alpha = a * 1.0;
    }
    
    opened by klaas 3
  • Swift error when *not* using Swift subspec

    Swift error when *not* using Swift subspec

    [!] Pods written in Swift can only be integrated as frameworks; this feature is still in beta. Add use_frameworks! to your Podfile or target to opt into using it. The Swift Pod being used is: Colours

    % pod --version 0.38.2

    opened by maciekish 2
  • Convert from hex string!

    Convert from hex string!

    One of these has an issue:

    • func hexString() -> String
    • init(hex: String)

    because I get different colors.

    ex. Color(hex: Color.successColor().hexString()) -> returns blue

    bug 
    opened by dcflow 2
  • Error:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: unknown option character `X' in: -Xlinker

    Error:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: unknown option character `X' in: -Xlinker

    in your updates(5.6.0) are experiencing problems similar to the following (still xcode6.1.1):

    http://stackoverflow.com/questions/24041962/static-linking-with-swift-xcode6-beta

    the official reason is that looks like this : "Xcode does not support building static libraries that include Swift code."

    opened by metasmile 2
  • Incorrect iOS system successColor

    Incorrect iOS system successColor

    Hi!

    First of all, I really like this lib. But I was surprised to find out that successColor is diffrent than green color from UISwitcher in iOS 7. In my understnding its a common green color in iOS. But if someone think diffrent lets try to discuss it here :)

    opened by mureev 2
  • change access control to public from internal

    change access control to public from internal

    I tried to use the Colours/Swift installed by cocoapods.

    But I cannot use any methods. Because access control is internal.

    If you extend a public or internal type, any new type members you add will have a default access level of internal.

    The Swift Programming Language (Swift 2.1): Access Control

    So, I added public

    My Environment is

    • swift 2.1
    • Xcode 7.1.1
    • cocoapods 0.39.0
    opened by sagaraya 1
  • Semantic issue on function fabsf warning in Xcode 6.3

    Semantic issue on function fabsf warning in Xcode 6.3

    I just update to Xcode 6.3 and the compiler sends me 2 warnings:

    Project/Pods/Colours/Colours.m:663:9: Absolute value function 'fabsf' given an argument of type 'double' but has parameter of type 'float' which may cause truncation of value

    Project/Pods/Colours/Colours.m:670:27: Absolute value function 'fabsf' given an argument of type 'double' but has parameter of type 'float' which may cause truncation of value

    I can make the change, but I'm not sure if its a great idea. If you need help, I can make the pull request.

    opened by gzfrancisco 1
  • pull request #56 hasn't been pushed to cocoapods

    pull request #56 hasn't been pushed to cocoapods

    it would be nice if there was a push to cocoa pods after that request was merged, because anyone using the sin Xcode 9 is going to see warnings for the comments

    opened by waterskier2007 3
Owner
Ben Gordon
Ben Gordon
Save the color of your moments. Remember your moments with colors you name.🎨

Pixel Palette ?? What was the color of the sunset yesterday? Or the color you would like to use in your vlog? Save the color of your moments with Pixe

Sue Cho 21 Aug 7, 2022
Convenience methods for creating color using RGBA hex string.

UIColor+Hex, now Swift. Convenience method for creating autoreleased color using RGBA hex string.

R0CKSTAR 1.2k Dec 23, 2022
System Color Picker - The macOS color picker as an app with more features

System Color Picker The macOS color picker as an app with more features Download Requires macOS 11 or later. Features Quickly copy, paste, and convert

Sindre Sorhus 758 Dec 24, 2022
ColorWheel Test - An attempt at creating a Color Wheel to be utilized for color picking in SwiftUI utlizing various tutuorials on youtube

This code focuses on creating a Color Wheel in which a user will be able to select a desired color to then be implemented in another project that will display that color in an LED connected to an arduino

Gerardo Cerpa 0 Jan 15, 2022
Yet another extension to manipulate colors easily in Swift and SwiftUI

DynamicColor provides powerful methods to manipulate colors in an easy way in Swift and SwiftUI. Requirements • Usage • Installation • Contribution •

Yannick Loriot 2.8k Dec 30, 2022
A pure Swift library that allows you to easily convert SwiftUI Colors to Hex String and vice versa.

iOS · macOS · watchOS · tvOS A pure Swift library that allows you to easily convert SwiftUI Colors to Hex String and vice versa. There is also support

Novem 3 Nov 20, 2022
ColorKit makes it easy to find the dominant colors of an image

ColorKit is your companion to work with colors on iOS. Features Installation Sample Project Contributing License Features Dominant Colors Col

Boris Emorine 569 Dec 29, 2022
All wikipedia colors implemented as easy to use UIColor extension 🌈

UIColor-WikiColors All wikipedia colors implemented as an easy to use UIColor extension. Have you ever tried using UIColor.lightBlue just to be welcom

Szymon Maślanka 58 Jul 30, 2022
Manage Colors, Integrate Night/Multiple Themes. (Unmaintained)

Easily integrate and high performance Providing UIKit and CoreAnimation category Read colour customisation from file Support different themes Generate

Draven 3.6k Dec 15, 2022
UIGradient - A simple and powerful library for using gradient layer, image, color

UIGradient is now available on CocoaPods. Simply add the following to your project Podfile, and you'll be good to go.

Đinh Quang Hiếu 247 Dec 1, 2022
SheetyColors is an action sheet styled color picker for iOS

?? Based on UIAlertController: The SheetyColors API is based on UIKit's UIAlertController. Simply add buttons to it as you would for any other Action Sheet by defining UIAlertAction instances. Therefore, it nicely integrates with the look & feel of all other native system dialogs. However, you can also chose to use the color picker it self without an action sheet.

Christoph Wendt 102 Nov 10, 2022
A tool to calculate the color ratio of UIImage in iOS.

UIImageColorRatio A tool to calculate the color ratio of UIImage in iOS. How to use UIImageColorRatio Get the color ratio of UIImage. let image = ...

Yanni Wang 王氩 34 Jan 1, 2023
iTunes 11 Style Color Art Detection for iOS

iTunes 11 Style Color Art Detection for iOS. Original implementation from Fred Leitz Port of ColorArt code from OS X to iOS. Usage #include <ColorArt/

Vinh Nguyen 132 Dec 14, 2021
ChromaColorPicker - An intuitive HSB color picker built in Swift

An intuitive HSB color picker built in Swift. Supports multiple selection handles and is customizable to your needs.

Jonathan Cardasis 536 Dec 29, 2022
HEX color handling as an extension for UIColor. Written in Swift.

SwiftHEXColors HEX color handling as an extension for UIColor. Written in Swift.

Thi Doãn 692 Dec 22, 2022
An attractive color generator for Swift. Ported from randomColor.js.

Random Color Swift Inspired by David Merfield's randomColor.js. It is a ported version to Swift. You can use the library to generate attractive random

Wei Wang 624 Jan 3, 2023
Flat UI color palette helpers written in Swift.

FlatUIColors (swift) install Make sure you have the latest version of CocoaPods (gem install cocoapods) that has Swift support. At the time of this wr

Bryn Bellomy 172 Dec 6, 2022
A UIColor extension with CSS3 Color names.

CSS3ColorsSwift Overview CSS3ColorsSwift provides a UIColor extension with Web Color names. Demo Run the demo project in the Demo directory without ca

WorldDownTown 67 Aug 6, 2022
Google Material Color Palette in Swift

Google Material Color in Swift Defined Google Material Color value ready to use in Swift refer to Google Material Design in Style/Color section ###How

Todsaporn Banjerdkit 48 Oct 30, 2019