UIlabel text color depending upon gradient color indicator [closed]
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];
精彩评论