UIlabel 文本颜色取决于渐变颜色指示器

发布于 2024-11-06 05:08:34 字数 203 浏览 1 评论 0原文

我正在做的应用程序,我需要显示高风险(红色)到低风险(黄色)意味着一条从红色开始到中间的其他多种颜色,最后以绿色结束......如果我的体重百分比是90%然后我需要为文本 90 显示绿色...同样,如果重量百分比为 25%,那么我需要根据百分比将 25 显示为红色等...那么我该如何做到这一点,使 uilabel 文本颜色取决于百分比??? 给一些示例代码,

提前谢谢...

im doing application where i need to show high risk (red color) to low risk(yellow color) means a strip starting from red color to another many colors in middle and finally ends in green color...if my weight percentage is 90% then i need to show green color for the text 90...and similarly if weight percentage is 25% then i need show 25 as red color and etc depending upon percentage... so how could i do this making uilabel text color depending upon percentage???
give some sample code,,

Thanks in advance...

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

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

发布评论

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

评论(3

柏拉图鍀咏恒 2024-11-13 05:08:34

你是如何计算百分比的。我假设您正在尝试这样做。根据一些公式/逻辑,您正在计算一些百分比。现在,如果百分比是 x,您希望以某种特定颜色向用户显示该 x 值。如果是这样,你可以这样做,

if(weight==25)
{
label.text = @"25";
label.textColor = [UIColor redColor];
}

如果你能更好地阐明你想要实现的目标,那将会非常有帮助。你的问题似乎并不能说明一切。

how are you calculating the percentage. Here is what I assume you are trying to do. Based on some formula/logic, you are calculating some percentage. Now if the percentage is x you want to show this x value in some particular color to the user. If it is so, you can do this,

if(weight==25)
{
label.text = @"25";
label.textColor = [UIColor redColor];
}

It will really help if you can elucidate better on what your are trying to accomplish. Your question doesn't seem to spell it all.

江南月 2024-11-13 05:08:34

if(weight >=90)[label setTextColor:[UIColor greenColor]];

if(weight >=90)[label setTextColor:[UIColor greenColor]];

少女的英雄梦 2024-11-13 05:08:34

更改绿色和红色的值,保持蓝色为 0,alpha 为 1。 UIColor *color = [UIColor colorWithRed:1.-(weight/100.) green:(weight/100.) blue:0.0阿尔法:1.0];

Change the values of green and red color, keep the blue at 0 and alpha at 1. UIColor *color = [UIColor colorWithRed:1.-(weight/100.) green:(weight/100.) blue:0.0 alpha:1.0];

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