从字符串中取颜色
来源:互联网 发布:python辗转相减法 编辑:程序博客网 时间:2024/05/01 03:35
+ (UIColor *)colorWithString:(NSString *)stringToConvert {
NSScanner *scanner = [NSScannerscannerWithString:stringToConvert];
if (![scannerscanString:@"{"intoString:NULL])return nil;
constNSUInteger kMaxComponents = 4;
CGFloat c[kMaxComponents];
NSUInteger i =0;
if (![scannerscanFloat:&c[i++]]) return nil;
while (1) {
if ([scannerscanString:@"}"intoString:NULL])break;
if (i >= kMaxComponents)return nil;
if ([scannerscanString:@","intoString:NULL]) {
if (![scannerscanFloat:&c[i++]]) return nil;
}else {
// either we're at the end of there's an unexpected character here
// both cases are error conditions
returnnil;
}
}
if (![scannerisAtEnd]) returnnil;
UIColor *color;
switch (i) {
case2: // monochrome
color = [UIColorcolorWithWhite:c[0]alpha:c[1]];
break;
case4: // RGB
color = [UIColorcolorWithRed:c[0]green:c[1] blue:c[2] alpha:c[3]];
break;
default:
color =nil;
}
return color;
}
+ (UIColor *)randomColor {
return [UIColorcolorWithRed:(CGFloat)RAND_MAX /random()
green:(CGFloat)RAND_MAX /random()
blue:(CGFloat)RAND_MAX /random()
alpha:1.0f];
}
- 从字符串中取颜色
- 从网页中取字符串
- 如何从字符串中取数组
- 从CString 字符串中取文件名
- 从指定颜色组中随机取色
- js 从10种颜色中随机取色,并每次取出的颜色不同
- Object-C 从字符串中取16进制数到byte数组
- Object-C 从字符串中取16进制数到byte数组
- Java正则从一段字符串中取email地址
- 从十六进制字符串获取颜色
- 口袋中有红黄蓝白黑5种颜色的球若干个。每次从口袋中任意取
- 字符串中取数字
- C++从文件中查找特定的字符串,并提取该字符串
- 从文件中查找特定的字符串,并提取该字符串
- 从collection中取op
- 从oracle表中随机取记录,产生随机数和随机字符串
- 从oracle表中随机取记录,产生随机数和随机字符串
- 从oracle表中随机取记录,产生随机数和随机字符串
- 来个经典的大字闹钟
- PHP 从数据库遍历返回json
- 查找算法之哈希查找
- RHEL 5.1 下面安装tftp服务
- xp怎么修改桌面图标?
- 从字符串中取颜色
- 查找算法整理之索引查找
- 求最长不增子序列、最长单调递减子序列、最长不降子序列、最长单调递增子序列长度
- VC6.0查看汇编代码
- ZigZag打印二叉树
- 常见的几种RuntimeException-
- 怎么截桌面的背景
- android--服务程序的例子
- mysql的重装