views:

306

answers:

3

Hello,

in some cases things you'd expect to solve within a sec turn out to become a lifetime adventure. This is one of these cases :)

All I wanted to do, is simply change the text color of one of my UITextViews. So far I tried:

UIColor *myColor = [UIColor colorWithHue:38 saturation:98 brightness:100 alpha:1.0];
[myTextView setTextColor:myColor];

OR

UIColor *myColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"colorImage.png"]];
[myTextView setTextColor:myColor]; 

Both seem to work fine for UILabels, but fail for UITextView elements. When I try [UIColor colorWithHue... I only get a reddish kinda color, no matter what values I choose (except values for black and white. They work). The colorWithPatternImage does not change textColor at all.

Strange isn't it? I obviously must be missing something. Help is very much appreciated. Thanks in advance.

+3  A: 

+colorWithHue:saturation:brightness:alpha:, like the other UIColor methods, takes values from 0 to 1, not 0 to 100. I would not expect +colorWithPatternImage: to work with text rendering at all, unless you feel like making your own Core Graphics-based drawing code.

Noah Witherspoon
+3  A: 

As Noah said, values are expected to be in the range [0, 1]. Try this instead and modify as necessary:

UIColor *myColor = [UIColor colorWithHue:0.38 saturation:0.98 brightness:1.0 alpha:1.0];
[myTextView setTextColor:myColor];
David Kanarek
Thanks, that makes sense. I'll give it a go in a bit and report back
Friendlydeveloper
A: 

Ok, I managed to get it to work. Thanks for all your help.

In case somebody runs into problems with the hue value, which is in degrees. Devide it by 360 before you use it in XCode.

Friendlydeveloper