Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1044821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:53:21+00:00 2026-05-16T15:53:21+00:00

Given a UIColor, I need to determine if it is light or dark. If

  • 0

Given a UIColor, I need to determine if it is “light” or “dark”. If I could access the hex value of the color, I could just check if it was greater than or less than a certain threshold hex number, but there appears to be no way to do that. Is there? Or is there another way I could check the brightness value of a UIColor?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:53:21+00:00Added an answer on May 16, 2026 at 3:53 pm

    You could install this Category for extending UIColor for knowing HSV/HSB and compare [aUIColor brightness]

    Edit:
    I found the same code in some github-hosted project, made a gist of it: https://gist.github.com/1252197


    #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 < 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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a tree, how to find the centre node in the tree so that
Given the following snippet: function countZeroes(array) { function counter(total, element) { return total +
Given three models: Document Asset AssetCategory A document accepts_nested_attributes_for assets (a document has_many assets),
given a relation like this: |Posts | |Taggins | |Tags| |------| ---------- ------ |
Given the follow: <table id=myTable> <tr> </tr> <tr> </tr> ... </table> I can clear
Given are a number of finite sets of integers, for example: A = {1,2,3}
Given two or more samples of text, specifically segments of code, what's the most
Given the existing buttons HTML: <div id=MB> <ul class=list> <li id=post-5><a href=#post-5>5</a></li> <li id=post-4><a
Given that a ThreadLocal variable holds different values for different threads, is it possible
I am trying to create a UITableView with subview and i using a tutorial

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.