Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top