当前位置:网站首页>颜色(color)转换为三刺激值(r/g/b)(干股)
颜色(color)转换为三刺激值(r/g/b)(干股)
2022-07-06 11:47:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
// 颜色转换 ##665522 — 三色值 + ( UIColor *)setFontColorWithString:( NSString *)color { NSString *cString = [[color stringByTrimmingCharactersInSet :[ NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString]; // 字符串个数必须大于等于6 if ([cString length] < 6) { return [UIColorclearColor]; } // 依据16进制来区分 if ([cString hasPrefix:@”0X”]) cString = [cString substringFromIndex:2]; if ([cString hasPrefix:@”#”]) cString = [cString substringFromIndex:1]; if ([cString length] != 6) return [UIColorclearColor]; // 分为r,g,b 子字符串 NSRange range; range.location = 0; range.length = 2; //r NSString *rString = [cString substringWithRange:range]; //g range.location = 2; NSString *gString = [cString substringWithRange:range]; //b range.location = 4; NSString *bString = [cString substringWithRange:range]; // 扫描r,g,b值 unsignedint r, g, b; [[NSScannerscannerWithString:rString] scanHexInt:&r]; [[NSScannerscannerWithString:gString] scanHexInt:&g]; [[NSScannerscannerWithString:bString] scanHexInt:&b]; return RgbHex2UIColor(r, g, b);
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/117138.html原文链接:https://javaforall.cn
边栏推荐
- Druid 数据库连接池 详解
- 凤凰架构3——事务处理
- How to access localhost:8000 by mobile phone
- LeetCode-1279. Traffic light intersection
- Learn to explore - use pseudo elements to clear the high collapse caused by floating elements
- MySQL must know and learn
- Mathematical knowledge -- code implementation of Gaussian elimination (elementary line transformation to solve equations)
- [pytorch] yolov5 train your own data set
- Excel 中VBA脚本的简单应用
- zabbix 代理服务器 与 zabbix-snmp 监控
猜你喜欢
[play with Linux] [docker] MySQL installation and configuration
算法面试经典100题,Android程序员最新职业规划
Problems encountered in using RT thread component fish
【翻译】云原生观察能力微调查。普罗米修斯引领潮流,但要了解系统的健康状况仍有障碍...
力扣101题:对称二叉树
Druid database connection pool details
Vmware虚拟机无法打开内核设备“\\.\Global\vmx86“的解决方法
【计算情与思】扫地僧、打字员、信息恐慌与奥本海默
A popular explanation will help you get started
Classic 100 questions of algorithm interview, the latest career planning of Android programmers
随机推荐
深度剖析原理,看完这一篇就够了
Vmware虚拟机无法打开内核设备“\\.\Global\vmx86“的解决方法
Introduction to enterprise lean management system
凤凰架构3——事务处理
[translation] supply chain security project in toto moved to CNCF incubator
Use of deg2rad and rad2deg functions in MATLAB
Mathematical knowledge -- code implementation of Gaussian elimination (elementary line transformation to solve equations)
The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
An error occurs when installing MySQL: could not create or access the registry key needed for the
打家劫舍III[后序遍历与回溯+动态规划]
在解决了 2961 个用户反馈后,我做出了这样的改变...
Microservice architecture debate between radical technologists vs Project conservatives
Learn to explore - use pseudo elements to clear the high collapse caused by floating elements
MySQL information schema learning (I) -- general table
测试用里hi
How to customize animation avatars? These six free online cartoon avatar generators are exciting at a glance!
Phoenix Architecture 3 - transaction processing
【计算情与思】扫地僧、打字员、信息恐慌与奥本海默
Mind map + source code + Notes + project, ByteDance + JD +360+ Netease interview question sorting
Interpretation of Dagan paper