objective-C不支持16进制的颜色表示,需要转换成rgb表示法
2012-07-25 16:08
357 查看
iphone应用变成中,不识别16进制的表示法,需要转化成rgb表示法
-(UIColor *) getColor:(NSString *)hexColor
{
unsigned int red, green, blue;
NSRange range;
range.length =2;
range.location =0;
[[NSScannerscannerWithString:[hexColor substringWithRange:range]]scanHexInt:&red];
range.location =2;
[[NSScannerscannerWithString:[hexColor substringWithRange:range]]scanHexInt:&green];
range.location =4;
[[NSScannerscannerWithString:[hexColor substringWithRange:range]]scanHexInt:&blue];
return [UIColor colorWithRed:(float)(red/255.0f)green:(float)(green/255.0f)blue:(float)(blue/255.0f)alpha:1.0f];
}
使用方法:
[nameLabelsetTextColor:[selfgetColor:@"5E4333"]];
或者直接到网上查找颜色相对应的rgb值
http://www.vitbbs.cn/RGB.html rgb颜色表
http://www.color-hex.com/color/5e4333 将十六进制直接转换成rgb值的网页工具
-(UIColor *) getColor:(NSString *)hexColor
{
unsigned int red, green, blue;
NSRange range;
range.length =2;
range.location =0;
[[NSScannerscannerWithString:[hexColor substringWithRange:range]]scanHexInt:&red];
range.location =2;
[[NSScannerscannerWithString:[hexColor substringWithRange:range]]scanHexInt:&green];
range.location =4;
[[NSScannerscannerWithString:[hexColor substringWithRange:range]]scanHexInt:&blue];
return [UIColor colorWithRed:(float)(red/255.0f)green:(float)(green/255.0f)blue:(float)(blue/255.0f)alpha:1.0f];
}
使用方法:
[nameLabelsetTextColor:[selfgetColor:@"5E4333"]];
或者直接到网上查找颜色相对应的rgb值
http://www.vitbbs.cn/RGB.html rgb颜色表
http://www.color-hex.com/color/5e4333 将十六进制直接转换成rgb值的网页工具
相关文章推荐
- objective-C不支持16进制的颜色表示,需要转换成rgb表示法(笔记)
- objective-C把16进制的颜色转换成RGB,包括透明度哦~
- C# RGB与16进制颜色转换方法
- Javascript转换RGB与16进制颜色值
- Android开发:setAlpha()方法和常用RGB颜色表----颜色, r g b分量数值(int), 16进制表示 一一对应
- iOS-swift-16进制颜色转换成RGB的例子
- Android开发:setAlpha()方法和常用RGB颜色表----颜色, r g b分量数值(int), 16进制表示 一一对应
- rgb颜色转换(16进制->10进制)
- RGB与16进制颜色转换的原理
- Android开发:setAlpha()方法和常用RGB颜色表----颜色, r g b分量数值(int), 16进制表示 一一对应
- IOS 将16进制颜色转换成RGB
- oc 颜色转换 16进制 转换成RGB
- 16进制的颜色怎么转换为我们iOS所用的RGB颜色
- 将普通的16进制颜色数值转换成UIColor表示形式的处理方法
- C# RGB颜色转换为16进制
- Android开发:setAlpha()方法和常用RGB颜色表----颜色, r g b分量数值(int), 16进制表示 一一对应
- C#RGB颜色与16进制之间的转换
- RGB,CMYK,HSB各种颜色表示的转换
- javascript16进制颜色转换为RGB
- Android开发:setAlpha()方法和常用RGB颜色表----颜色, r g b分量数值(int), 16进制表示 一一对应