CLRColorUtils
Objective-C
@interface CLRColorUtils : NSObject
Swift
class CLRColorUtils : NSObject
Color utilities with support for hex, RBG, arithmetic RBG, and integer colors
-
Convert the hex color values to a hex color
Declaration
Objective-C
+ (NSString *)toColorFromHexRed:(NSString *)red andGreen:(NSString *)green andBlue:(NSString *)blue;
Swift
class func toColor(fromHexRed red: String!, andGreen green: String!, andBlue blue: String!) -> String!
Parameters
red
red hex color in format RR or R
green
green hex color in format GG or G
blue
blue hex color in format BB or B
Return Value
hex color in format #RRGGBB
-
Convert the hex color values to a hex color, shorthanded when possible
Declaration
Objective-C
+ (NSString *)toColorShorthandFromHexRed:(NSString *)red andGreen:(NSString *)green andBlue:(NSString *)blue;
Swift
class func toColorShorthand(fromHexRed red: String!, andGreen green: String!, andBlue blue: String!) -> String!
Parameters
red
red hex color in format RR or R
green
green hex color in format GG or G
blue
blue hex color in format BB or B
Return Value
hex color in format #RGB or #RRGGBB
-
Convert the hex color values to a hex color including an opaque alpha value of FF
Declaration
Objective-C
+ (NSString *)toColorWithAlphaFromHexRed:(NSString *)red andGreen:(NSString *)green andBlue:(NSString *)blue;
Swift
class func toColorWithAlpha(fromHexRed red: String!, andGreen green: String!, andBlue blue: String!) -> String!
Parameters
red
red hex color in format RR or R
green
green hex color in format GG or G
blue
blue hex color in format BB or B
Return Value
hex color in format #AARRGGBB
-
Convert the hex color values to a hex color including an opaque alpha value of FF or F, shorthanded when possible
Declaration
Objective-C
+ (NSString *)toColorShorthandWithAlphaFromHexRed:(NSString *)red andGreen:(NSString *)green andBlue:(NSString *)blue;
Swift
class func toColorShorthandWithAlpha(fromHexRed red: String!, andGreen green: String!, andBlue blue: String!) -> String!
Parameters
red
red hex color in format RR or R
green
green hex color in format GG or G
blue
blue hex color in format BB or B
Return Value
hex color in format #ARGB or #AARRGGBB
-
Convert the hex color values to a hex color
Declaration
Objective-C
+ (NSString *)toColorWithAlphaFromHexRed:(NSString *)red andGreen:(NSString *)green andBlue:(NSString *)blue andAlpha:(NSString *)alpha;
Swift
class func toColorWithAlpha(fromHexRed red: String!, andGreen green: String!, andBlue blue: String!, andAlpha alpha: String!) -> String!
Parameters
red
red hex color in format RR or R
green
green hex color in format GG or G
blue
blue hex color in format BB or B
alpha
alpha hex color in format AA or A, null to not include alpha
Return Value
hex color in format #AARRGGBB or #RRGGBB
-
Convert the hex color values to a hex color, shorthanded when possible
Declaration
Objective-C
+ (NSString *)toColorShorthandWithAlphaFromHexRed:(NSString *)red andGreen:(NSString *)green andBlue:(NSString *)blue andAlpha:(NSString *)alpha;
Swift
class func toColorShorthandWithAlpha(fromHexRed red: String!, andGreen green: String!, andBlue blue: String!, andAlpha alpha: String!) -> String!
Parameters
red
red hex color in format RR or R
green
green hex color in format GG or G
blue
blue hex color in format BB or B
alpha
alpha hex color in format AA or A, null to not include alpha
Return Value
hex color in format #ARGB, #RGB, #AARRGGBB, or #RRGGBB
-
Convert the RBG values to a color integer
Declaration
Objective-C
+ (int)toColorFromRed:(int)red andGreen:(int)green andBlue:(int)blue;
Swift
class func toColor(fromRed red: Int32, andGreen green: Int32, andBlue blue: Int32) -> Int32
Parameters
red
red integer color inclusively between 0 and 255
green
green integer color inclusively between 0 and 255
blue
blue integer color inclusively between 0 and 255
Return Value
integer color
-
Convert the RBG values to a color unsigned integer
Declaration
Objective-C
+ (unsigned int)toUnsignedColorFromRed:(int)red andGreen:(int)green andBlue:(int)blue;
Swift
class func toUnsignedColor(fromRed red: Int32, andGreen green: Int32, andBlue blue: Int32) -> UInt32
Parameters
red
red integer color inclusively between 0 and 255
green
green integer color inclusively between 0 and 255
blue
blue integer color inclusively between 0 and 255
Return Value
unsigned integer color
-
Convert the RBG values to a color integer including an opaque alpha value of 255
Declaration
Objective-C
+ (int)toColorWithAlphaFromRed:(int)red andGreen:(int)green andBlue:(int)blue;
Swift
class func toColorWithAlpha(fromRed red: Int32, andGreen green: Int32, andBlue blue: Int32) -> Int32
Parameters
red
red integer color inclusively between 0 and 255
green
green integer color inclusively between 0 and 255
blue
blue integer color inclusively between 0 and 255
Return Value
integer color
-
Convert the RBG values to a color unsigned integer including an opaque alpha value of 255
Declaration
Objective-C
+ (unsigned int)toUnsignedColorWithAlphaFromRed:(int)red andGreen:(int)green andBlue:(int)blue;
Swift
class func toUnsignedColorWithAlpha(fromRed red: Int32, andGreen green: Int32, andBlue blue: Int32) -> UInt32
Parameters
red
red integer color inclusively between 0 and 255
green
green integer color inclusively between 0 and 255
blue
blue integer color inclusively between 0 and 255
Return Value
unsigned integer color
-
Convert the RBGA values to a color integer
Declaration
Objective-C
+ (int)toColorWithAlphaFromRed:(int)red andGreen:(int)green andBlue:(int)blue andAlpha:(int)alpha;
Swift
class func toColorWithAlpha(fromRed red: Int32, andGreen green: Int32, andBlue blue: Int32, andAlpha alpha: Int32) -> Int32
Parameters
red
red integer color inclusively between 0 and 255
green
green integer color inclusively between 0 and 255
blue
blue integer color inclusively between 0 and 255
alpha
alpha integer color inclusively between 0 and 255, -1 to not include alpha
Return Value
integer color
-
Convert the RBGA values to a color unsigned integer
Declaration
Objective-C
+ (unsigned int)toUnsignedColorWithAlphaFromRed:(int)red andGreen:(int)green andBlue:(int)blue andAlpha:(int)alpha;
Swift
class func toUnsignedColorWithAlpha(fromRed red: Int32, andGreen green: Int32, andBlue blue: Int32, andAlpha alpha: Int32) -> UInt32
Parameters
red
red integer color inclusively between 0 and 255
green
green integer color inclusively between 0 and 255
blue
blue integer color inclusively between 0 and 255
alpha
alpha integer color inclusively between 0 and 255, -1 to not include alpha
Return Value
unsigned integer color
-
Convert the RGB integer to a hex single color
Declaration
Objective-C
+ (NSString *)toHexFromRGB:(int)color;
Swift
class func toHex(fromRGB color: Int32) -> String!
Parameters
color
integer color inclusively between 0 and 255
Return Value
hex single color in format FF
-
Convert the arithmetic RGB float to a hex single color
Declaration
Objective-C
+ (NSString *)toHexFromArithmeticRGB:(float)color;
Swift
class func toHex(fromArithmeticRGB color: Float) -> String!
Parameters
color
float color inclusively between 0.0 and 1.0
Return Value
hex single color in format FF
-
Convert the hex single color to a RBG integer
Declaration
Objective-C
+ (int)toRGBFromHex:(NSString *)color;
Swift
class func toRGB(fromHex color: String!) -> Int32
Parameters
color
hex single color in format FF or F
Return Value
integer color inclusively between 0 and 255
-
Convert the arithmetic RGB float to a RBG integer
Declaration
Objective-C
+ (int)toRGBFromArithmeticRGB:(float)color;
Swift
class func toRGB(fromArithmeticRGB color: Float) -> Int32
Parameters
color
float color inclusively between 0.0 and 1.0
Return Value
integer color inclusively between 0 and 255
-
Convert the hex single color to an arithmetic RBG float
Declaration
Objective-C
+ (float)toArithmeticRGBFromHex:(NSString *)color;
Swift
class func toArithmeticRGB(fromHex color: String!) -> Float
Parameters
color
hex single color in format FF or F
Return Value
float color inclusively between 0.0 and 1.0
-
Convert the RGB integer to an arithmetic RBG float
Declaration
Objective-C
+ (float)toArithmeticRGBFromRGB:(int)color;
Swift
class func toArithmeticRGB(fromRGB color: Int32) -> Float
Parameters
color
integer color inclusively between 0 and 255
Return Value
float color inclusively between 0.0 and 1.0
-
Convert red, green, and blue arithmetic values to HSL (hue, saturation, lightness) values
Declaration
Objective-C
+ (float *)toHSLFromArithmeticRed:(float)red andGreen:(float)green andBlue:(float)blue;
Swift
class func toHSL(fromArithmeticRed red: Float, andGreen green: Float, andBlue blue: Float) -> UnsafeMutablePointer<Float>!
Parameters
red
red color inclusively between 0.0 and 1.0
green
green color inclusively between 0.0 and 1.0
blue
blue color inclusively between 0.0 and 1.0
Return Value
HSL array where: 0 = hue, 1 = saturation, 2 = lightness
-
Convert red, green, and blue integer values to HSL (hue, saturation, lightness) values
Declaration
Objective-C
+ (float *)toHSLFromRed:(int)red andGreen:(int)green andBlue:(int)blue;
Swift
class func toHSL(fromRed red: Int32, andGreen green: Int32, andBlue blue: Int32) -> UnsafeMutablePointer<Float>!
Parameters
red
red color inclusively between 0 and 255
green
green color inclusively between 0 and 255
blue
blue color inclusively between 0 and 255
Return Value
HSL array where: 0 = hue, 1 = saturation, 2 = lightness
-
Convert HSL (hue, saturation, and lightness) values to RGB arithmetic values
Declaration
Objective-C
+ (float *)toArithmeticRGBFromHue:(float)hue andSaturation:(float)saturation andLightness:(float)lightness;
Swift
class func toArithmeticRGB(fromHue hue: Float, andSaturation saturation: Float, andLightness lightness: Float) -> UnsafeMutablePointer<Float>!
Parameters
hue
hue value inclusively between 0.0 and 360.0
saturation
saturation inclusively between 0.0 and 1.0
lightness
lightness inclusively between 0.0 and 1.0
Return Value
arithmetic RGB array where: 0 = red, 1 = green, 2 = blue
-
Convert HSL (hue, saturation, and lightness) values to RGB integer values
Declaration
Objective-C
+ (int *)toRGBFromHue:(float)hue andSaturation:(float)saturation andLightness:(float)lightness;
Swift
class func toRGB(fromHue hue: Float, andSaturation saturation: Float, andLightness lightness: Float) -> UnsafeMutablePointer<Int32>!
Parameters
hue
hue value inclusively between 0.0 and 360.0
saturation
saturation inclusively between 0.0 and 1.0
lightness
lightness inclusively between 0.0 and 1.0
Return Value
RGB integer array where: 0 = red, 1 = green, 2 = blue
-
Get the hex red color from the hex string
Declaration
Objective-C
+ (NSString *)redHexFromHex:(NSString *)hex;
Swift
class func redHex(fromHex hex: String!) -> String!
Parameters
hex
hex color
Return Value
hex red color in format RR
-
Get the hex green color from the hex string
Declaration
Objective-C
+ (NSString *)greenHexFromHex:(NSString *)hex;
Swift
class func greenHex(fromHex hex: String!) -> String!
Parameters
hex
hex color
Return Value
hex green color in format GG
-
Get the hex blue color from the hex string
Declaration
Objective-C
+ (NSString *)blueHexFromHex:(NSString *)hex;
Swift
class func blueHex(fromHex hex: String!) -> String!
Parameters
hex
hex color
Return Value
hex blue color in format BB
-
Get the hex alpha color from the hex string if it exists
Declaration
Objective-C
+ (NSString *)alphaHexFromHex:(NSString *)hex;
Swift
class func alphaHex(fromHex hex: String!) -> String!
Parameters
hex
hex color
Return Value
hex alpha color in format AA or null
-
Get the red color from color integer
Declaration
Objective-C
+ (int)redFromColor:(int)color;
Swift
class func red(fromColor color: Int32) -> Int32
Parameters
color
color integer
Return Value
red color
-
Get the red color from color unsigned integer
Declaration
Objective-C
+ (int)redFromUnsignedColor:(unsigned int)color;
Swift
class func red(fromUnsignedColor color: UInt32) -> Int32
Parameters
color
color unsigned integer
Return Value
red color
-
Get the green color from color integer
Declaration
Objective-C
+ (int)greenFromColor:(int)color;
Swift
class func green(fromColor color: Int32) -> Int32
Parameters
color
color integer
Return Value
green color
-
Get the green color from color unsigned integer
Declaration
Objective-C
+ (int)greenFromUnsignedColor:(unsigned int)color;
Swift
class func green(fromUnsignedColor color: UInt32) -> Int32
Parameters
color
color unsigned integer
Return Value
green color
-
Get the blue color from color integer
Declaration
Objective-C
+ (int)blueFromColor:(int)color;
Swift
class func blue(fromColor color: Int32) -> Int32
Parameters
color
color integer
Return Value
blue color
-
Get the blue color from color unsigned integer
Declaration
Objective-C
+ (int)blueFromUnsignedColor:(unsigned int)color;
Swift
class func blue(fromUnsignedColor color: UInt32) -> Int32
Parameters
color
color unsigned integer
Return Value
blue color
-
Get the alpha color from color integer
Declaration
Objective-C
+ (int)alphaFromColor:(int)color;
Swift
class func alpha(fromColor color: Int32) -> Int32
Parameters
color
color integer
Return Value
alpha color
-
Get the alpha color from color unsigned integer
Declaration
Objective-C
+ (int)alphaFromUnsignedColor:(unsigned int)color;
Swift
class func alpha(fromUnsignedColor color: UInt32) -> Int32
Parameters
color
color unsigned integer
Return Value
alpha color
-
Shorthand the hex color if possible
Declaration
Objective-C
+ (NSString *)shorthandHex:(NSString *)color;
Swift
class func shorthandHex(_ color: String!) -> String!
Parameters
color
hex color
Return Value
shorthand hex color or original value
-
Expand the hex if it is in shorthand
Declaration
Objective-C
+ (NSString *)expandShorthandHex:(NSString *)color;
Swift
class func expandShorthandHex(_ color: String!) -> String!
Parameters
color
hex color
Return Value
expanded hex color or original value
-
Shorthand the hex single color if possible
Declaration
Objective-C
+ (NSString *)shorthandHexSingle:(NSString *)color;
Swift
class func shorthandHexSingle(_ color: String!) -> String!
Parameters
color
hex single color
Return Value
shorthand hex color or original value
-
Expand the hex single if it is in shorthand
Declaration
Objective-C
+ (NSString *)expandShorthandHexSingle:(NSString *)color;
Swift
class func expandShorthandHexSingle(_ color: String!) -> String!
Parameters
color
hex single color
Return Value
expanded hex color or original value
-
Check if the hex color value is valid
Declaration
Objective-C
+ (BOOL)isValidHex:(NSString *)color;
Swift
class func isValidHex(_ color: String!) -> Bool
Parameters
color
hex color
Return Value
true if valid
-
Validate the hex color value
Declaration
Objective-C
+ (void)validateHex:(NSString *)color;
Swift
class func validateHex(_ color: String!)
Parameters
color
hex color
-
Check if the hex single color value is valid
Declaration
Objective-C
+ (BOOL)isValidHexSingle:(NSString *)color;
Swift
class func isValidHexSingle(_ color: String!) -> Bool
Parameters
color
hex single color
Return Value
true if valid
-
Validate the hex single color value
Declaration
Objective-C
+ (void)validateHexSingle:(NSString *)color;
Swift
class func validateHexSingle(_ color: String!)
Parameters
color
hex single color
-
Check if the RBG integer color is valid, inclusively between 0 and 255
Declaration
Objective-C
+ (BOOL)isValidRGB:(int)color;
Swift
class func isValidRGB(_ color: Int32) -> Bool
Parameters
color
decimal color
Return Value
true if valid
-
Validate the RBG integer color is inclusively between 0 and 255
Declaration
Objective-C
+ (void)validateRGB:(int)color;
Swift
class func validateRGB(_ color: Int32)
Parameters
color
decimal color
-
Check if the arithmetic RGB float color is valid, inclusively between 0.0 and 1.0
Declaration
Objective-C
+ (BOOL)isValidArithmeticRGB:(float)color;
Swift
class func isValidArithmeticRGB(_ color: Float) -> Bool
Parameters
color
decimal color
Return Value
true if valid
-
Validate the arithmetic RGB float color is inclusively between 0.0 and 1.0
Declaration
Objective-C
+ (void)validateArithmeticRGB:(float)color;
Swift
class func validateArithmeticRGB(_ color: Float)
Parameters
color
decimal color
-
Check if the HSL hue float value is valid, inclusively between 0.0 and 360.0
Declaration
Objective-C
+ (BOOL)isValidHue:(float)hue;
Swift
class func isValidHue(_ hue: Float) -> Bool
Parameters
hue
hue value
Return Value
true if valid
-
Validate the HSL hue float value is inclusively between 0.0 and 360.0
Declaration
Objective-C
+ (void)validateHue:(float)hue;
Swift
class func validateHue(_ hue: Float)
Parameters
hue
hue value
-
Check if the HSL saturation float value is valid, inclusively between 0.0 and 1.0
Declaration
Objective-C
+ (BOOL)isValidSaturation:(float)saturation;
Swift
class func isValidSaturation(_ saturation: Float) -> Bool
Parameters
saturation
saturation value
Return Value
true if valid
-
Validate the HSL saturation float value is inclusively between 0.0 and 1.0
Declaration
Objective-C
+ (void)validateSaturation:(float)saturation;
Swift
class func validateSaturation(_ saturation: Float)
Parameters
saturation
saturation value
-
Check if the HSL lightness float value is valid, inclusively between 0.0 and 1.0
Declaration
Objective-C
+ (BOOL)isValidLightness:(float)lightness;
Swift
class func isValidLightness(_ lightness: Float) -> Bool
Parameters
lightness
lightness value
Return Value
true if valid
-
Validate the HSL lightness float value is inclusively between 0.0 and 1.0
Declaration
Objective-C
+ (void)validateLightness:(float)lightness;
Swift
class func validateLightness(_ lightness: Float)
Parameters
lightness
lightness value