从uicolor的六角形颜色

编程入门 行业动态 更新时间:2024-10-24 16:30:12
本文介绍了从uicolor的六角形颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在将uicolor转换为十六进制颜色时遇到了问题,这里是我发现的

CGColorRef colorref = [[Colorview_ backgroundColor] CGColor]; int numComponents = CGColorGetNumberOfComponents(colorref); if(numComponents == 4){ const CGFloat * components = CGColorGetComponents(colorref); int hexValue = 0xFF0000 * components [0] + 0xFF00 * components [1] + 0xFF * components [2]; NSString * hexString = [NSString stringWithFormat:@#%d,hexValue]; }

这段代码给了我#5576149(例如)hexString,看看有7个数字不是6,它不是一个十六进制颜色,任何帮助将不胜感激,thx。

NSString * hexString = [NSString stringWithFormat:@#%d,hexValue];

您将其格式化为包含%d的数字

你想用十六进制格式化为%x或%X - 也许作为字符串%s我没有检查函数正在做什么以及 int hexValue 是持有

d或i有符号十进制整数392

x无符号十六进制整数7fa

X无符号十六进制整数(大写字母)7FA

i have a problem in converting uicolor to hex color, here what i found

CGColorRef colorref = [[Colorview_ backgroundColor] CGColor]; int numComponents = CGColorGetNumberOfComponents(colorref); if (numComponents == 4) { const CGFloat *components = CGColorGetComponents(colorref); int hexValue = 0xFF0000*components[0] + 0xFF00*components[1] + 0xFF*components[2]; NSString *hexString = [NSString stringWithFormat:@"#%d", hexValue]; }

this code is giving me #5576149 (for example) for hexString, us you see there are 7 digits not 6, it's not a hex color, any help will be appreciated, thx.

解决方案

NSString *hexString = [NSString stringWithFormat:@"#%d", hexValue];

You are formatting it as a digit with %d

You want to format it as hex with %x or %X -- maybe as string %s I didnt check what the function is doing and what int hexValue is holding

d or i Signed decimal integer 392

x Unsigned hexadecimal integer 7fa

X Unsigned hexadecimal integer (capital letters) 7FA

更多推荐

从uicolor的六角形颜色

本文发布于:2023-11-30 02:41:14,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:颜色   uicolor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!