将UIColor转换为RGB值
来源:互联网 发布:u盘安装linux双系统 编辑:程序博客网 时间:2024/05/06 10:50
//将UIColor转换为RGB值- (NSMutableArray *) changeUIColorToRGB:(UIColor *)color{ NSMutableArray *RGBStrValueArr = [[NSMutableArray alloc] init]; NSString *RGBStr = nil; //获得RGB值描述 NSString *RGBValue = [NSString stringWithFormat:@"%@",color]; //将RGB值描述分隔成字符串 NSArray *RGBArr = [RGBValue componentsSeparatedByString:@" "]; //获取红色值 int r = [[RGBArr objectAtIndex:1] intValue] * 255; RGBStr = [NSString stringWithFormat:@"%d",r]; [RGBStrValueArr addObject:RGBStr]; //获取绿色值 int g = [[RGBArr objectAtIndex:2] intValue] * 255; RGBStr = [NSString stringWithFormat:@"%d",g]; [RGBStrValueArr addObject:RGBStr]; //获取蓝色值 int b = [[RGBArr objectAtIndex:3] intValue] * 255; RGBStr = [NSString stringWithFormat:@"%d",b]; [RGBStrValueArr addObject:RGBStr]; //返回保存RGB值的数组 return [RGBStrValueArr autorelease];}
//16进制颜色(html颜色值)字符串转为UIColor+(UIColor *) hexStringToColor: (NSString *) stringToConvert{ NSString *cString = [[stringToConvert stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString]; // String should be 6 or 8 characters if ([cString length] < 6) return [UIColor blackColor]; // strip 0X if it appears if ([cString hasPrefix:@"0X"]) cString = [cString substringFromIndex:2]; if ([cString hasPrefix:@"#"]) cString = [cString substringFromIndex:1]; if ([cString length] != 6) return [UIColor blackColor]; // Separate into r, g, b substrings NSRange range; range.location = 0; range.length = 2; NSString *rString = [cString substringWithRange:range]; range.location = 2; NSString *gString = [cString substringWithRange:range]; range.location = 4; NSString *bString = [cString substringWithRange:range]; // Scan values unsigned int r, g, b; [[NSScanner scannerWithString:rString] scanHexInt:&r]; [[NSScanner scannerWithString:gString] scanHexInt:&g]; [[NSScanner scannerWithString:bString] scanHexInt:&b]; return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];}
- (NSMutableArray *) changeUIColorToRGB:(UIColor *)color{ size_t n = CGColorGetNumberOfComponents(color.CGColor); const CGFloat *rgba = CGColorGetComponents(color.CGColor); NSMutableArray *resultArr = [NSMutableArray arrayWithCapacity:n]; for (int i=0; i<n; i++) { [resultArr addObject:[NSNumber numberWithFloat:rgba]]; } return resultArr;}
【OBJC类扩展之Hex值颜色转换】UIColor+Hex#import <UIKit/UIKit.h>@interface UIColor (Hex)+ (UIColor *)colorWithHex:(long)hexColor;+ (UIColor *)colorWithHex:(long)hexColor alpha:(float)opacity;@end#import "UIColor+Hex.h"@implementation UIColor (Hex)+ (UIColor*) colorWithHex:(long)hexColor;{ return [UIColor colorWithHex:hexColor alpha:1.]; }+ (UIColor *)colorWithHex:(long)hexColor alpha:(float)opacity{ float red = ((float)((hexColor & 0xFF0000) >> 16))/255.0; float green = ((float)((hexColor & 0xFF00) >> 8))/255.0; float blue = ((float)(hexColor & 0xFF))/255.0; return [UIColor colorWithRed:red green:green blue:blue alpha:opacity]; } @end
0 0
- 将UIColor转换为RGB值
- 将UIColor转换为RGB值
- 将RGB颜色值转换为UIColor
- //将UIColor转换为RGB值
- 将UIColor转换为RGB值
- 将UIColor转换为RGB值
- 将UIColor转换为RGB值
- IOS 将RGB颜色值转换为UIColor
- IOS 将十六进制RGB颜色值转换为UIColor
- iphone-将UIColor转换成RGB
- ios UIColor转化为RGB值
- UIColor获取RGB值
- UIColor获取RGB值
- UIColor获取RGB值
- ios客户端学习-颜色将16位值转换成rgb值,UIColor与字符串互转
- 将RGB值转换为灰度值的简单算法
- 将RGB值转换为灰度值的简单算法
- 利用opencv将raw转换为rgb
- 九度1021(字符串水题)
- Eclipse搭建Python开发环境,项目中不出现PyDev选项
- linux 内核模块编译的Makefile模板
- sublime text使用指南
- ARM--------ADS1.2 debug出错 error starting external process process error code 87(0x57)
- 将UIColor转换为RGB值
- 重构L**MM图标浏览模式的文件管理器
- 临摹
- 搜索指定文件夹下的指定文件(只能用于一级目录)
- 大家好 我是新手 多多指教
- Android-EditText(自定义带删除功能的EditText)
- EDIUS 视音频制作标准教程(第2版)21堂课高清1280X720 25Pmp4格式 含同步素材 edius初学者必备装备
- Aix6.1搭建tomcat7.0.57步骤
- 山东分公司电风扇地方撒旦法撒旦发生大幅gas的gas大力开发和萨德克里夫个