UI给开发的效果图非常多时候标注着十六进制的Color,而程序中用到的往往是UIColor能够用例如以下方法去转换:

(UIColor *)RGBColorFromHexString:(NSString *)color alpha:(float)alpha { //color的值相似#fffeee,alpha的值相似1.0为透明度
int nums[6] = {0};
for (int i = 1; i < [color length]; i++) {
int temp = [color characterAtIndex:i];
if (temp >= '0' && temp <= '9') {
nums[i-1] = [color characterAtIndex:i] - '0';
}else if(temp >= 'A' && temp <= 'F') {
nums[i-1] = [color characterAtIndex:i] - 'A' + 10;
}else if(temp >= 'a' && temp <= 'f') {
nums[i-1] = [color characterAtIndex:i] - 'a' + 10;
}else {
return [UIColor whiteColor];
} }
float rValue = (nums[0] * 16 + nums[1]) / 255.0f;
float gValue = (nums[2] *16 + nums[3]) / 255.0f;
float bValue = (nums[4] *16 + nums[5]) / 255.0f;
UIColor *rgbColor = [UIColor colorWithRed:rValue green:gValue blue:bValue alpha:alpha];
return rgbColor;
}

最新文章

  1. redis学习笔记
  2. Android开发之MVP模式的使用
  3. [leetcode] 题型整理之二叉树
  4. linux basis --- common commands
  5. JQuery 动画及一些小知识点
  6. Error LNK2019: unresolved external symbol &quot;char * __stdcall _com_util::ConvertBSTRToString(wchar_t *)&quot;
  7. 【转】linux下awk内置函数的使用(split/substr/length)
  8. iOS 开发-- Runtime 1小时入门教程
  9. 非常实用的Android Studio快捷键
  10. iOS tableview和 Collection复用机制
  11. IDEA SpringBoot 打包(jar)
  12. 【python35小工具】b站弹幕保存
  13. static类型的变量
  14. day34 并发编程之生产者消费者模型 队列
  15. MySQL_插入更新 ON DUPLICATE KEY UPDATE
  16. swift - iOS10之后的加速器
  17. JavaScript -- Window-Scroll
  18. 洛谷P1445 樱花
  19. Cocos2d-x执行时错误:Cocos2d: Get data from file(xxx.xxx) failed!
  20. LeetCode: Insertion Sort List 解题报告

热门文章

  1. HDU 4767
  2. UI_UISlider控件
  3. hdu4870 Rating (高斯消元或者dp)
  4. win10 bcdedit加入vhdx启动
  5. 使用Jquery Ajax请求 下载压缩文件
  6. Spark Streaming概念学习系列之SparkStreaming运行原理
  7. Oracle 新手语法记录
  8. Swagger 隐藏具体API
  9. form&amp;input
  10. 洛谷P3358 最长k可重区间集问题(费用流)