views:

55

answers:

2

I have a UISlider that is supposed to update the color of a textlabel. Now I want the user to be able to choose between all colors in the spectrum (sort of all anyway). I was thinking of using this UISlider to represent the colors and when dragging the slider the value/color changes.

I know the spectrum is not sequential like: [0,0,0]...[255,0,0]...[255,1,0]...[255,255,0] etc. So: any tip on how I can implement this?

+1  A: 

Color is at least a two or three dimensional selection. And a slider only provides a scalar output. If you want a smoothly changing selection using only a scalar parameter, you might try drawing a path line on some color chart (or a functional representation thereof) and select a point on that path parametrically.

hotpaw2
I had this idea aswell, but the animation would not be as nice. Gonna look into it anyway.
sebrock
A: 

Yes, color is a multidimensional value, but there are different ways to slice those dimensions. I think a hue, saturation, brightness constructor, rather than RGB, will give you exactly the effect you want. For example, often I will generate a random color with [UIColor colorWithHue:<random float in [0,1]> saturation:1.f brightness:1.f alpha:1.f].

Slide hue linearly from 0 to 1, with saturation and brightness fixed at the most legible (or whatever) values.

zem
interesting solution. I'll try it out!
sebrock
Perfect, it was exactly what I needed!
sebrock