SYCSSColor
SYCSSColor 是一个将 CSS 颜色转换为 CGColor 或 UIColor 的非常方便的库。它为您在使用下一个应用中使用了 CSS 颜色提供了一个机会。
基于 iOS 的 CSS 颜色。
功能
- 所有 CSS 颜色支持
- 使用 LRUCache 来存储 CGColor
- 使用
gperf
生成一个完美的哈希函数来存储 NameColor - 支持 ColorSpaceSRGB, ColorSpaceLinearRGB, ColorSpaceDisplayP3。
- 支持 CMYK, HSL, HSV
- 支持混合颜色
SYCSSColor
将CSS颜色转换为CGColor或UIColor的最简单用例
字符串有前缀hash(#)
NSString *fuchsiaString = @"#FF00FF";
SYColor *fuchsia = [SYColor colorWithString: fuchsiaString];
// fuchsia.red == 255;
// fuchsia.green == 0;
// fuchsia.blue == 255;
字符串是像" fuchsia"那样的颜色名称
SYColor *fuchsia = [SYColor colorWithString: @"fuchsia"];
// fuchsia.red == 255;
// fuchsia.green == 0;
// fuchsia.blue == 255;
字符串是rgb( )语法或rgba( ),它支持百分比(%)
NSString *fuchsiaRgbString = @"rgb(100%, 0%, 100%)";
NSString *fuchsiaRgbPercentString = @"rgb(255, 0, 255)";
NSString *fuchsiaRgbaString = @"rgba(255, 0, 255, 0.8)";
SYColor *fuchsiaRgb = [SYColor colorWithString:@"fuchsia"];
SYColor *fuchsiaRgbPercent = [SYColor colorWithString:@"fuchsia"];
SYColor *fuchsiaRgba = [SYColor colorWithString:@"fuchsia"];
// fuchsia.red == 255;
// fuchsia.green == 0;
// fuchsia.blue == 255;
混合颜色
当两种颜色混合时,其中必须有一种不是不透明的
SYColor *red = [SYColor colorWithString:@"red"];
SYColor *green = [SYColor colorWithString:@"green"];
SYColor *blendColor = [SYColor blendFrom:red to:green progress:0.9];
// blendColor.red == 26;
// blendColor.green == 115;
// blendColor.blue == 0;
CachedCGColor
CachedCGColor
被存储在TinyLRUCache
中以加快速度。
安装
苹果插件仓库
- 将
pod 'SYCSSColor'
添加到您的Podfile中。 - 运行
pod install
或pod update
。 - 导入<SYCSSColor/SYCSSColor.h>。
系统要求
此库需要iOS 10.0+
和Xcode 11.0+
。
许可协议
SYCSSColor遵循MIT许可协议。详情见LICENSE文件。