Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could install <a href="http://bravobug.com/news/?p=448" rel="nofollow noreferrer">this Category</a> for extending <code>UIColor</code> for knowing HSV/HSB and compare <code>[aUIColor brightness]</code></p> <p>Edit:<br> I found the same code in some <a href="https://github.com/davidblackuk/Dashboards/blob/a8bb2d0bb7103782042107919192712602d29de9/IOSDashBoards/IOSDashBoards/UIColor-HSVAdditions.m" rel="nofollow noreferrer">github-hosted project</a>, made a gist of it: <a href="https://gist.github.com/1252197" rel="nofollow noreferrer">https://gist.github.com/1252197</a></p> <hr> <pre><code>#import "UIColor-HSVAdditions.h" @implementation UIColor (UIColor_HSVAdditions) +(struct hsv_color)HSVfromRGB:(struct rgb_color)rgb { struct hsv_color hsv; CGFloat rgb_min, rgb_max; rgb_min = MIN3(rgb.r, rgb.g, rgb.b); rgb_max = MAX3(rgb.r, rgb.g, rgb.b); hsv.val = rgb_max; if (hsv.val == 0) { hsv.hue = hsv.sat = 0; return hsv; } rgb.r /= hsv.val; rgb.g /= hsv.val; rgb.b /= hsv.val; rgb_min = MIN3(rgb.r, rgb.g, rgb.b); rgb_max = MAX3(rgb.r, rgb.g, rgb.b); hsv.sat = rgb_max - rgb_min; if (hsv.sat == 0) { hsv.hue = 0; return hsv; } if (rgb_max == rgb.r) { hsv.hue = 0.0 + 60.0*(rgb.g - rgb.b); if (hsv.hue &lt; 0.0) { hsv.hue += 360.0; } } else if (rgb_max == rgb.g) { hsv.hue = 120.0 + 60.0*(rgb.b - rgb.r); } else /* rgb_max == rgb.b */ { hsv.hue = 240.0 + 60.0*(rgb.r - rgb.g); } return hsv; } -(CGFloat)hue { struct hsv_color hsv; struct rgb_color rgb; rgb.r = [self red]; rgb.g = [self green]; rgb.b = [self blue]; hsv = [UIColor HSVfromRGB: rgb]; return (hsv.hue / 360.0); } -(CGFloat)saturation { struct hsv_color hsv; struct rgb_color rgb; rgb.r = [self red]; rgb.g = [self green]; rgb.b = [self blue]; hsv = [UIColor HSVfromRGB: rgb]; return hsv.sat; } -(CGFloat)brightness { struct hsv_color hsv; struct rgb_color rgb; rgb.r = [self red]; rgb.g = [self green]; rgb.b = [self blue]; hsv = [UIColor HSVfromRGB: rgb]; return hsv.val; } -(CGFloat)value { return [self brightness]; } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload