I have a table view with 17 sections with 4 rows each. I want to set random different colors for each section in such a way that the colors dont repeat, and every time the table is reloaded their respective colors change. For example: If a table header has Gray color, then its cells should have different shades of gray.. and.. If a table header has green color, then its cells should have different shades of green, and so on.
How to do this
thankx in advance
I have a table view with 17 sections with 4 rows each. I want
Share
So the solution to this is to use a color space that uses hue, saturation, and luminance. The hue is either 360 degrees or 2 radians. If you need colors, you start splitting the circle into the number of slices you need, create the value in that color space (the hue from the slice, set saturation to full on, luminance to full on. In your case its 360/17 is your slice degree.
We used this at a company I worked at a few years ago. There is probably sample C code around for this but you’ll have to search on your own to try and find it. Its not that hard to do.
Apple has a nice guide on color and color spaces, you can read it in the Xcode documentation pane by searching on “Color and Color Spaces”.