Code Monkey home page Code Monkey logo

colours's Introduction

ScreenShot

Build Status

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'

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.

Color Palette

infoBlueColorinfoBlueColorsuccessColorsuccessColorwarningColorwarningColor
dangerColordangerColorantiqueWhiteColorantiqueWhiteColoroldLaceColoroldLaceColor
ivoryColorivoryColorseashellColorseashellColorghostWhiteColorghostWhiteColor
snowColorsnowColorlinenColorlinenColorblack25PercentColorblack25PercentColor
black50PercentColorblack50PercentColorblack75PercentColorblack75PercentColorwarmGrayColorwarmGrayColor
coolGrayColorcoolGrayColorcharcoalColorcharcoalColortealColortealColor
steelBlueColorsteelBlueColorrobinEggColorrobinEggColorpastelBlueColorpastelBlueColor
turquoiseColorturquoiseColorskyBlueColorskyBlueColorindigoColorindigoColor
denimColordenimColorblueberryColorblueberryColorcornflowerColorcornflowerColor
babyBlueColorbabyBlueColormidnightBlueColormidnightBlueColorfadedBlueColorfadedBlueColor
icebergColoricebergColorwaveColorwaveColoremeraldColoremeraldColor
grassColorgrassColorpastelGreenColorpastelGreenColorseafoamColorseafoamColor
paleGreenColorpaleGreenColorcactusGreenColorcactusGreenColorchartreuseColorchartreuseColor
hollyGreenColorhollyGreenColoroliveColoroliveColoroliveDrabColoroliveDrabColor
moneyGreenColormoneyGreenColorhoneydewColorhoneydewColorlimeColorlimeColor
cardTableColorcardTableColorsalmonColorsalmonColorbrickRedColorbrickRedColor
easterPinkColoreasterPinkColorgrapefruitColorgrapefruitColorpinkColorpinkColor
indianRedColorindianRedColorstrawberryColorstrawberryColorcoralColorcoralColor
maroonColormaroonColorwatermelonColorwatermelonColortomatoColortomatoColor
pinkLipstickColorpinkLipstickColorpaleRoseColorpaleRoseColorcrimsonColorcrimsonColor
eggplantColoreggplantColorpastelPurpleColorpastelPurpleColorpalePurpleColorpalePurpleColor
coolPurpleColorcoolPurpleColorvioletColorvioletColorplumColorplumColor
lavenderColorlavenderColorraspberryColorraspberryColorfuschiaColorfuschiaColor
grapeColorgrapeColorperiwinkleColorperiwinkleColororchidColororchidColor
goldenrodColorgoldenrodColoryellowGreenColoryellowGreenColorbananaColorbananaColor
mustardColormustardColorbuttermilkColorbuttermilkColorgoldColorgoldColor
creamColorcreamColorlightCreamColorlightCreamColorwheatColorwheatColor
beigeColorbeigeColorpeachColorpeachColorburntOrangeColorburntOrangeColor
pastelOrangeColorpastelOrangeColorcantaloupeColorcantaloupeColorcarrotColorcarrotColor
mandarinColormandarinColorchiliPowderColorchiliPowderColorburntSiennaColorburntSiennaColor
chocolateColorchocolateColorcoffeeColorcoffeeColorcinnamonColorcinnamonColor
almondColoralmondColoreggshellColoreggshellColorsandColorsandColor
mudColormudColorsiennaColorsiennaColordustColordustColor

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 to and from a UIColor

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

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 for the keys: @"r",@"g",@"b",@"a".

NSDictionary *colorDict = [[UIColor seafoamColor] rgbaDictionary];
UIColor *newColor = [UIColor colorFromRGBADictionary:colorDict];

HSBA Array & Dictionary to and from a UIColor

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.

NSArray *colorArray = [[UIColor seafoamColor] hsbaArray];
NSDictionary *colorDict = [[UIColor seafoamColor] hsbaDictionary];

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

Generating white or black that contrasts with a UIColor

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];

Generating a 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];

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.

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.

colours's People

Contributors

ajfigueroa avatar bennyguitar avatar brianpartridge avatar craigwalton avatar dcritelli avatar jksk avatar kilakev avatar mureev avatar palleas avatar pierrotdelalune avatar pridechung avatar steffex avatar

Stargazers

 avatar

Forkers

jasonworking

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.