Colours–颜色库,包含各种定制好的颜色和方法,可以简化相关的开发工作.
项目主页: Colours
最新示例: 点击下载
pod 'Colours'
把 Colours.h 和 Colours.m拖进你的工程里,在需要的地方引入头文件即可:
#import "Colours.h"
Colours 预定义了100 多种颜色,用法和使用iOS系统预定义的方式一样:
[UIColor indigoColor]; // indigoColor是Colours预定义的一种颜色.
UIColor *newColor = [UIColor colorFromHexString:@"#f587e4"]; NSString *hexString = [newColor hexString];
RGBA数组与颜色的相互转换
NSArray *colorArray = [[UIColor seafoamColor] rgbaArray];// 数组中存储四个NSNumber对象分别代表RGBA的四个值,取值范围 0-1. UIColor *newColor = [UIColor colorFromRGBAArray:colorArray];
RGBA字典与颜色的相互转换
预定义的四个键是:
kColoursRGBA_R
kColoursRGBA_G
kColoursRGBA_B
kColoursRGBA_A
NSDictionary *colorDict = [[UIColor seafoamColor] rgbaDictionary];
UIColor *newColor = [UIColor colorFromRGBADictionary:colorDict]; // 你可以获取某个单独的值: NSNumber *r = colorDict[kColoursRGBA_R];
NSArray *colorArray = [[UIColor seafoamColor] hsbaArray];// 数组中存储四个NSNumber,分别代表H(色调),S(色饱和度),B(亮度),A(透明度)的值. NSDictionary *colorDict = [[UIColor seafoamColor] hsbaDictionary];
与RGBA与颜色的相互转换类似,预定义的键是:
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];
与RGBA与颜色的相互转换类似,预定义的键是:
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];
与RGBA与颜色的相互转换用法相似,预定义的键是:
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];
colorComponents 方法会返回一个字典,包含RGBA, HSBA, CIE_LAB和CMYK预定义的所有键:
NSDictionary *components = [someColor colorComponents]; CGFloat H = components[kColoursHSBA_H]; CGFloat L = components[kColoursCIE_L];
如果你一次只想某个某一条颜色相关的信息,可以使用下面的方法:
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];
// 取值范围 0->1 UIColor *lighterColor = [[UIColor seafoamColor] lighten:0.25f]; UIColor *darkerColor = [[UIColor seafoamColor] darken:0.25f];
// 根据给定的颜色,自动与之能形成对比色的黑色或白色. UIColor *contrastingColor = [[UIColor seafoamColor] blackOrWhiteContrastingColor];
// 返回一个给定颜色的互补色:色调改变,色调和饱和度不变. UIColor *complementary = [[UIColor seafoamColor] complementaryColor];
// 此处的差别,综合考虑了人的感官,数学统计算法等,不是一般的RGB差值. CGFloat distance = [someColor distanceFromColor:someOtherColor type:ColorDistanceCIE94]; BOOL isNoticablySimilar = distance < threshold;
使用 colorSchemeOfType 方法可以基于某一个颜色,产生四个新的漂亮合适的颜色,并把全部五个颜色以数组形式返回.同一种颜色,不同的方案也会产生不同的颜色组合.
NSArray *colorScheme = [color colorSchemeOfType:ColorSchemeType];
可选颜色方案:
下面是基于[UIColor seafoamColor]颜色的不同颜色方案返回值的示例: