将 NSString 转换为十六进制值并应用于 UILabel

发布于 2024-10-07 22:30:30 字数 120 浏览 6 评论 0原文

我有一个 6 位十六进制格式的颜色代码,例如 3333fb,现在我必须将其转换为 0X3333fb 十六进制值,并且必须将其设置为 UILabel 文本颜色或表视图单元格文本标签颜色。

我怎样才能实现这个目标?

I have a color code in 6 digit hex format like 3333fb, now I have to convert it to 0X3333fb hexadecimal value and have to set it as UILabel text color or tableview cell textlabel color.

How can I achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不在是我 2024-10-14 22:30:30

试试这个宏:

// Get a UIColor from a hex value --> UIColor* c = HEXCOLOR(0xff00ffff);
#define HEXCOLOR(c) [UIColor colorWithRed:((c>>24)&0xFF)/255.0 \
                                    green:((c>>16)&0xFF)/255.0 \
                                     blue:((c>>8)&0xFF)/255.0 \
                                    alpha:((c)&0xFF)/255.0]

当你想要一个 UIColor 时,只需这样做:

HEXCOLOR(0x3333fbFF)

Try this macro:

// Get a UIColor from a hex value --> UIColor* c = HEXCOLOR(0xff00ffff);
#define HEXCOLOR(c) [UIColor colorWithRed:((c>>24)&0xFF)/255.0 \
                                    green:((c>>16)&0xFF)/255.0 \
                                     blue:((c>>8)&0xFF)/255.0 \
                                    alpha:((c)&0xFF)/255.0]

When you want to have a UIColor simply do this:

HEXCOLOR(0x3333fbFF)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文