IOS假设将一个十六进制的color转换成UIColor,非常有用
ios 一个 转换成 非常 有用 十六进制 Color 假设
2023-09-11 14:15:00 时间
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; }
相关文章
- (NO.00002)iOS游戏精灵战争雏形(十一)
- iOS开发-常用第三方开源框架介绍(你了解的ios只是冰山一角)
- IOS 30多个iOS常用动画,带详细注释
- iOS开发UI篇—IOS开发中Xcode的一些使用技巧
- iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局
- iOS开发UI篇—使用嵌套模型完成的一个简单汽车图标展示程序
- iOS开发UI篇—ios应用数据存储方式(归档)
- IOS使用Auto Layout中的VFL适配
- iOS网络编程-ASIHTTPRequest框架同步请求
- iOS开发那些事--编写OCUnit测试方法-逻辑测试方法
- 苹果 iOS推送 APNS(本人亲测总结)
- ios swift5 tableView cell 自适应高度 自动行高
- ios swift bytes:[UInt8]合成一个Int数:左为高位,右为低位
- iOS swift UITextField 限制输入指定的字符 限制输入字符的长度
- Ios开发之 -- js和ios的交互
- Mac Appium iOS自动化测试环境搭建教程
- ios swift 从另一个数组总过滤掉当前数组中的元素