Colours-color library, including 100 predefined colors and methods, and colour100

Source: Internet
Author: User

Colours-color library, including 100 predefined colors and methods, and colour100

Introduction

Colours-color library, including a variety of 100 predefined colors and methods, can simplify color-related development.

Project homepage: Colours

Latest example: Click to download

Get started with Cocoapods
pod 'Colours'
Manual Installation

Drag Colours. h and Colours. m into your project and introduce the header file as needed:

#import "Colours.h"
Use a palette, a set of predefined colors

Click here for details: 100 predefined colors

Use predefined colors

Colours predefines more than 100 colors, in the same way as the iOS system predefines:

[UIColor indigoColor]; // indigoColor is a color predefined by Colours.
Color-related tools and methods hexadecimal string and color conversion
UIColor *newColor = [UIColor colorFromHexString:@"#f587e4"];NSString *hexString = [newColor hexString];
Mutual conversion between RGBA and color. Mutual conversion between RGBA array and color
NSArray * colorArray = [[UIColor seafoamColor] rgbaArray]; // four NSNumber objects stored in the array represent the four values of RGBA, respectively. The value range is 0-1.UIColor * newColor = [UIColor colorFromRGBAArray: colorArray];
Mutual conversion between RGBA dictionary and color

The predefined four keys are:

  • kColoursRGBA_R
  • kColoursRGBA_G
  • kColoursRGBA_B
  • kColoursRGBA_A
NSDictionary * colorDict = [[UIColor seafoamColor] rgbaDictionary];UIColor * newColor = [UIColor colorFromRGBADictionary: colorDict]; // you can obtain a separate value: NSNumber * r = colorDict [kColoursRGBA_R];
HSBA array and color conversion
NSArray * colorArray = [[UIColor seafoamColor] hsbaArray]; // four nsnumbers are stored in the array, representing H (tone), S (color saturation), B (brightness ), A (transparency) value. NSDictionary * colorDict = [[UIColor seafoamColor] hsbaDictionary];
Mutual conversion between HSBA and colors

Similar to the conversion between RGBA and color, the predefined key is:

  • Kcolourshsb_h color
  • Kcolourshsb_s color saturation
  • KColoursHSBA_ B color brightness
  • Kcolourshsb_a transparency
NSArray *colorArray = [[UIColor seafoamColor] hsbaArray];NSDictionary *colorDict = [[UIColor seafoamColor] hsbaDictionary];UIColor *newColor1 = [UIColor colorFromHSBAArray:colorArray];UIColor *newColor2 = [UIColor colorFromHSBADictionary:colorDictionary];
Conversion between CIELAB and colors

Similar to the conversion between RGBA and color, the predefined key is:

  • 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];
Conversion between CMYK and colors

Similar to the conversion of RGBA and color, the predefined key is:

  • KColoursCMYK_C green
  • KColoursCMYK_M red
  • KColoursCMYK_Y yellow
  • KColoursCMYK_K black
NSArray *colorArray = [[UIColor seafoamColor] cmykArray];NSDictionary *colorDict = [[UIColor seafoamColor] cmykDictionary];UIColor *newColor1 = [UIColor colorFromCMYKArray:colorArray];UIColor *newColor2 = [UIColor colorFromCMYKDictionary:colorDictionary];
Obtain all color information

The colorComponents method returns a dictionary containing all the keys pre-defined by RGBA, HSBA, CIE_LAB, and CMYK:

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

If you only want a certain color information at a time, you can use the following method:

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];
Color brightened/dimmed
// Value range: 0-> 1 UIColor * lighterColor = [[UIColor seafoamColor] lighten: 0.25f]; UIColor * darkerColor = [UIColor seafoamColor] darken: 0.25f];
Obtain contrast colors
// Depending on the given color, it will automatically form a black or white contrast. UIColor * contrastingColor = [[UIColor seafoamColor] blackOrWhiteContrastingColor];
Obtain complementary colors
// Returns a complementary color of a given color: The color and saturation remain unchanged. UIColor * complementary = [[UIColor seafoamColor] complementaryColor];
Obtains the difference between two colors.
// The difference here, taking into account the human senses, mathematical statistics algorithms, etc., is not a general RGB difference. CGFloat distance = [someColor distanceFromColor: someOtherColor type: ColorDistanceCIE94]; BOOL isNoticablySimilar = distance <threshold;
Multiple corresponding color schemes are generated based on one color.

The colorSchemeOfType method can be used to generate four beautiful and appropriate colors based on a certain color, and return all five colors in an array. for the same color, different schemes also produce different color combinations.

NSArray *colorScheme = [color colorSchemeOfType:ColorSchemeType];

Optional color scheme:

  • ColorSchemeAnalagous approximate color
  • ColorSchemeMonochromatic monochrome
  • ColorSchemeTriad mixed color
  • ColorSchemeComplementary complementary colors

The following is an example of the return values of different color schemes based on [UIColor seafoamColor] colors:

ColorSchemeAnalagous

ColorSchemeMonochromatic

ColorSchemeTriad

ColorSchemeComplementary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.