Is there any algorithm that will create different shades for given Hex or RGB value? I have tried with alpha increasing & decreasing but it's not looking good with light colors(ex: white color).
Asked
Active
Viewed 1,206 times
4
-
There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs. – Neeku Aug 12 '14 at 09:29
-
Maybe something like [this](http://stackoverflow.com/questions/11598043/get-slightly-lighter-and-darker-color-from-uicolor)? – The Paramagnetic Croissant Aug 12 '14 at 09:29
-
2use `HBS` instead or `RGB`, and you can play with the `brightness`, but please do not create another fifty shades of grey. – holex Aug 12 '14 at 09:36
-
@holex : thank you so much for your suggestion(play with brightness). It is working . – Javeed Aug 12 '14 at 10:22
1 Answers
10
The best way to do this is using HSB colour space.
It's how I did the left hand section of the keyboard in my latest app...
The "shade" of the colour is the H
value and S
value. You can then change the brightness of it by adjusting the B
value.
So if you had a colour like...
HSB - 0.5, 0.9, 0.9 - very light blue
You could create darker shades by changing the B value...
HSB - 0.5, 0.9, 0.3 - dark blue of the same shade.
Create HSB colours like...
UIColor *color = [UIColor colorWithHue:0.5 saturation:0.9 brightness:0.4 alpha:1.0];
In my app I had a "lightest brightness" and a "darkest brightness".
The I worked out the change in brightness for each section by dividing the difference between them by the number of sections.
Using a for
loop I was able to easily create the different section colours.

Fogmeister
- 76,236
- 42
- 207
- 306
-
1While this is a good answer, the link to your app bugs me a little. Seems a screenshot would have been enough, more "future proof" and less gratuitous self-promoting. – Guillaume Algis Aug 12 '14 at 09:52
-
3@GuillaumeAlgis edited. Hey, we all have to get word out there somehow :P edited now though. – Fogmeister Aug 12 '14 at 10:01