IOS gets the cmyk value of the UIColor object, and ios gets the uicolorcmyk
/**
* Obtain the CMYK string value of the UIColor object.
*/
-(NSString *) getCMYKStringValueByColor :( UIColor *) originColor {
// Method provided by the Colours class extension
NSDictionary * cmykDict = [selfgetCMYKValueByColor: originColor];
Return [NSStringstringWithFormat: @ "(% 0.2f, % 0.2f, % 0.2f, % 0.2f )",
[CmykDict [@ "C"] floatValue],
[CmykDict [@ "M"] floatValue],
[CmykDict [@ "Y"] floatValue],
[CmykDict [@ "K"] floatValue];
}
/**
* Obtain the cmyk value of the UIColor object.
*
* @ Return
*/
-(NSDictionary *) getCMYKValueByColor :( UIColor *) originColor
{
// Convert RGB to CMY
NSDictionary * rgb = [selfgetRGBDictionaryByColor: originColor];
CGFloat C = 1-[rgb [@ "R"] floatValue];
CGFloat M = 1-[rgb [@ "G"] floatValue];
CGFloat Y = 1-[rgb [@ "B"] floatValue];
// Find K
CGFloat K = MIN (1, MIN (C, MIN (Y, M )));
If (K = 1 ){
C = 0;
M = 0;
Y = 0;
}
Else {
Void (^ newCMYK) (CGFloat *);
NewCMYK = ^ (CGFloat * x ){
* X = (* x-K)/(1-K );
};
NewCMYK (& C );
NewCMYK (& M );
NewCMYK (& Y );
}
Return @ {@ "C": @ (C ),
@ "M": @ (M ),
@ "Y": @ (Y ),
@ "K": @ (K )};
}
/**
* Obtain the rgb value of the UIColor object.
*
* @ Return refers to the dictionary object that contains rgb values.
*/
-(NSDictionary *) getRGBDictionaryByColor :( UIColor *) originColor
{
CGFloat r = 0, g = 0, B = 0, a = 0;
If ([selfrespondsToSelector: @ selector (getRed: green: blue: alpha :)]) {
[OriginColorgetRed: & rgreen: & gblue: & balpha: & a];
}
Else {
ConstCGFloat * components = CGColorGetComponents (originColor. CGColor );
R = components [0];
G = components [1];
B = components [2];
A = components [3];
}
Return @ {@ "R": @ (r ),
@ "G": @ (g ),
@ "B": @ (B ),
@ "A": @ ()};
}