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 6626539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:54:15+00:00 2026-05-25T21:54:15+00:00

I have found answers to this question that explain how to convert an NSString

  • 0

I have found answers to this question that explain how to convert an NSString hex into a UIColor (I have done this) and others explaining how to convert RGB to HSB, and others explaining how to determine lightness and darkness of RGB, but I’m wondering if there is a more direct way of figuring this out that does not involve going hex->UIColor->rgb->hsb->b.
Hex->hsb, for instance? Or hex->rgb->brightness calculation?

I’ve got backgrounds that change color each time the view loads (hex values from XML), and I need to have the text on top change to white or black accordingly so it’ll stay legible.

Help would be much appreciated, I’ve been kicking this around for days now.

  • 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-25T21:54:15+00:00Added an answer on May 25, 2026 at 9:54 pm

    See Formula to determine brightness of RGB color.

    Hex colors are usually RRGGBB or RRGGBBAA (alpha).

    how to convert hexadecimal to RGB

    To get three ints instead of a UIColor, you can modify the answer from that to:

    void rgb_from_hex(char *hexstring, int *red, int *green, int *blue) {
        // convert everything after the # into a number
        long x = strtol(hexstring+1, NULL, 16);
    
        // extract the bytes
        *blue = x & 0xFF;
        *green = (x >> 8) & 0xFF;
        *red = (x >> 16) & 0xFF;
    }
    
    // The above function is used like this:
    int main (int argc, const char * argv[])
    {
        int r,g,b;
        rgb_from_hex("#123456", &r, &g, &b);
        printf("r=%d, g=%d, b=%d\n", r, g, b);
    }
    

    (The function will probably only correctly handle RGB, not RGBA.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Often, when searching for answers, I have found that certain websites will allow you
I've searched SO and found several answers obviously related to my question, and have
I understand that this question is similar to others asking about Java Properties, and
I've run into a strange problem with Ruby that I can't explain. I have
This is my first time using StackOverflow myself. I have found many answers to
I have been looking around and even found a couple of related answers and
Hopefully a simple question although one I have found impossible to answer myself using
Here is a hum-dinger of a problem that I have not found an answer
I have an small question I didn't found an answer yet: how do I
I have faced this problem when working with ORACLE 10g. I read the answers

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.