SYCSSColor is a remarkably convenient library for translated CSS color to CGColor or UIColor. It provides you a chance to use CSS color in your next app.
Base on CSS color for iOS.
- All CSS Color Support
- LRUCache to stored CGColor
- Use
gperf
to generate a perfect hash function to store NameColor - Support ColorSpaceSRGB, ColorSpaceLinearRGB, ColorSpaceDisplayP3.
- Support CMYK, HSL, HSV
- Support blend color
The simplest use-case to translated CSS color to CGColor or UIColor:
NSString *fuchsiaString = @"#FF00FF";
SYColor *fuchsia = [SYColor colorWithString: fuchsiaString];
// fuchsia.red == 255;
// fuchsia.green == 0;
// fuchsia.blue == 255;
SYColor *fuchsia = [SYColor colorWithString: @"fuchsia"];
// fuchsia.red == 255;
// fuchsia.green == 0;
// fuchsia.blue == 255;
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;
When two color blend which One of them must not opaque:
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;
A CachedCGColor
is stored in TinyLRUCache
to speed up.
- Add
pod 'SYCSSColor'
to your Podfile. - Run
pod install
orpod update
. - Import <SYCSSColor/SYCSSColor.h>.
This library requires iOS 10.0+
and Xcode 11.0+
.
SYCSSColor is provided under the MIT license. See LICENSE file for details.