UIlabel 文本颜色取决于渐变颜色指示器
我正在做的应用程序,我需要显示高风险(红色)到低风险(黄色)意味着一条从红色开始到中间的其他多种颜色,最后以绿色结束......如果我的体重百分比是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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你是如何计算百分比的。我假设您正在尝试这样做。根据一些公式/逻辑,您正在计算一些百分比。现在,如果百分比是 x,您希望以某种特定颜色向用户显示该 x 值。如果是这样,你可以这样做,
如果你能更好地阐明你想要实现的目标,那将会非常有帮助。你的问题似乎并不能说明一切。
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,
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.
if(weight >=90)[label setTextColor:[UIColor greenColor]];
if(weight >=90)[label setTextColor:[UIColor greenColor]];
更改绿色和红色的值,保持蓝色为 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];