Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-c : How to create different shades of a color

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).

enter image description here

like image 336
Javeed Avatar asked Dec 25 '22 05:12

Javeed


1 Answers

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...

enter image description here

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.

like image 178
Fogmeister Avatar answered Dec 28 '22 09:12

Fogmeister