iOS 获取UIColor对象的rgb值。

/**

*  获取UIColor对象的rgb值。

*

*  @param originColor

*

*  @return

*/

- (NSString *)getHexStringByColor:(UIColor *)originColor

{

NSDictionary *colorDic
= [self getRGBDictionaryByColor:originColor];

int r = [colorDic[@"R"]
floatValue] * 255;

int g = [colorDic[@"G"]
floatValue] * 255;

int b = [colorDic[@"B"]
floatValue] * 255;

NSString *red = [NSString
stringWithFormat:@"%02x", r];

NSString *green = [NSString
stringWithFormat:@"%02x", g];

NSString *blue = [NSString
stringWithFormat:@"%02x", b];

return [NSString
stringWithFormat:@"#%@%@%@", red, green, blue];

}

- (NSDictionary *)getRGBDictionaryByColor:(UIColor *)originColor

{

CGFloat r=0,g=0,b=0,a=0;

if ([self
respondsToSelector:@selector(getRed:green:blue:alpha:)]) {

[originColor
getRed:&r green:&g
blue:&b alpha:&a];

}

else {

const CGFloat *components =
CGColorGetComponents(originColor.CGColor);

r = components[0];

g = components[1];

b = components[2];

a = components[3];

}

return @{@"R":@(r),

@"G":@(g),

@"B":@(b),

@"A":@(a)};

}

时间: 2024-10-16 04:19:38

iOS 获取UIColor对象的rgb值。的相关文章

iOS获取UIColor对象的RGB值

- (NSDictionary *)getRGBDictionaryByColor:(UIColor *)originColor { CGFloat r=0,g=0,b=0,a=0; if ([self respondsToSelector:@selector(getRed:green:blue:alpha:)]) { [originColor getRed:&r green:&g blue:&b alpha:&a]; } else { const CGFloat *com

iOS获取UIColor对象的CMYK值

/** * 获取UIColor对象的CMYK字符串值. */ - (NSString *)getCMYKStringValueByColor:(UIColor *)originColor{ // Method provided by the Colours class extension NSDictionary *cmykDict = [self getCMYKValueByColor:originColor]; return [NSString stringWithFormat:@"(%0.

iOS 获取UIColor对象的lab字符串值。

- (NSString *)getCIELABString:(UIColor *)originColor  { // Method provided by the Colours class extension NSDictionary *cieDict = [self getCIE_LabArrayByColor:originColor ]; return [NSString stringWithFormat:@"(%0.2f, %0.2f, %0.2f)", [cieDict[@&

iOS 获取UIColor对象的HSB字符串值。

/** *  获取UIColor对象的HSB字符串值. * */ - (NSString *)getHSBStringByColor:(UIColor *)originColor { // Method provided by the Colours class extension NSDictionary *hsbDict = [self getHSBAValueByColor:originColor]; return [NSString stringWithFormat:@"(%0.2f,

获取JSON对象的属性值

1.问题背景 有一个json对象,其中有键值对,那怎样获取json对象中属性值 2.实现源码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">

泛型获取对应对象类型属性值

1.传入一个泛型List, 2.获取泛型的类型Type type对象, 3.然后获取type 对象的对应属性PropertyInfo proInfo对象, 4.然后根据属性对象proInfo 获取泛型对象T的对应属性值 代码如下: private List<T> Test<T>(List<T> lst, string aa) { List<T> l = new List<T>(); Type t = typeof(T); string cc =

IOS中利用宏将RGB值转换为UIColor(转)

可以在pch文件中定义宏,这样整个项目就都可以用了! 1 #define UIColorFromRGBValue(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

js获取json对象的key值

 <script type="text/javascript">  getJson('age'); function getJson(key){ var jsonObj={"name":"傅红雪","age":"24","profession":"刺客"}; //1.使用eval方法 var eValue=eval('jsonObj.'+key); ale

js获取json对象的属性值

// var responseData = response.data.result; for (var r in responseData) { if (responseData[r]["visible"] == 0) { responseData[r]["visible"] = "是"; } else { responseData[r]["visible"] = "否"; } } 原文地址:https: