How to get RGB components of a custom color in ios
Asked Answered
C

4

10

I would like to set custom color programmatically using the method
[UIColor colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha];
For which i need to know the value of RBG components.
I would like to know is there any way by which i can get the RBG components of a custom color so that i can use them in the above mentioned method.

Conover answered 10/1, 2012 at 19:56 Comment(0)
M
35

You can use the DigitalColor Meter.app included with every Mac OS X install. You can find it in ~/Applications/Utilities/DigitalColor Meter.app. Use it to inspect the RGB values of any pixel you mouse over. Once you have the values, you just need to divide them by 255.0 because +colorWithRed:green:blue:alpha: is expecting a floating point value between 0 and 1.

[UIColor colorWithRed:83.0f/255.0f green:217.0f/255.0f blue:58.0f/255.0f alpha:1.0f];
Meehan answered 10/1, 2012 at 19:59 Comment(0)
C
9

You can use Xcode itself to get RGB value of custom color:

Click the arrow for the Color box and in the resulting dialog box choose others. enter image description here

And then you can use RGB Slider option to get RGB values

enter image description here

Cantle answered 16/3, 2013 at 0:27 Comment(0)
S
2

To match a color exactly, there is a great utility called "DigitalColor Meter" located in Applications/Utilities/ that can get the RGB for anything on your screen. Take a screen shot of the color you want to replicate, then use this tool to get the information.

Sawhorse answered 10/1, 2012 at 19:59 Comment(0)
C
2

Actually there is no need for using DigitalColor Meter instead we can use the small Search Icon search icon on color picker in the Interface Builder with which we can exactly adjust the color that we like.It is also possible to look up the color values using RBG scales available in it.

Conover answered 21/12, 2012 at 4:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.