开发者

UIlabel text color depending upon gradient color indicator [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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 gree开发者_运维百科n 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...


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.


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


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];

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜