How to get RGB components of a custom color in ios - iphone

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.

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];

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.
And then you can use RGB Slider option to get RGB values

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.

Actually there is no need for using DigitalColor Meter instead we can use the small 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.

Related

How can I make each Packed Bubble a different color?

I have a Packed Bubble dashboard. My Y axis is a list of names and my X axis is a decimal. I want each differing number to be a different color. Can I do this manually?
If you want to color each bubble with a separate color just use the field that each bubble represent in the color shelf. If I understood your data correctly, each bubble basically represents one campaign, so you should use that as the color.
You can manually assign color using Color>Edit Color and assigning the color of your choice.
See image 1.
If you want to color your bubbles based on your measure AVg(NPV/Marketing $) you can do as Alex Blakemore mentioned and use your measure as a stepped color or gradient.
You can use Color>Edit Color here too , in this case manually assigning color is a bit difficult. But if you play with number of steps, the gradient pre-select, etc, you can usually get very close to what ever your wanted it to look like.
Put your numeric field on the color shelf, and either edit the colors to use a stepped set of colors - or change the field to be discrete and choose individual colors to taste.

Read "simple" transparent PNG in Matlab

I am trying to use PNG images as Toolbar icons. I am currently reading them with imread an set the corresponding CData value.
Now I have some images with transparency. There is no alpha channel (I found some threads with solutions for that), but I get some kind of "Simple Transparency". The imfread function returns "simple" for the Transparency field and a vector of values between 0 and 1 for the SimpleTransparencyData field.
I couldn't find any information about this transparency type neither in the Matlab help nor the internet. So I would like to know if it is possible to show the transparent image in the toolbar directly, or if not how to composite the transparent values with the toolbar's background color.
In summary you set the CData value to be a NaN to represent transparency.
See this article that I wrote on undocumentedmatlab.com which describes how to do it for uicontrols.
For a toolbar icon you modify the CData property in the same way - the primary difference is that you dont need to modify the backgroundcolor property.
I did a quick test on the only solution I could probably imagine and it really seems to work:
I forgot to mention, that I am using indexed PNG files for this. But this sort of transparency seems to imply this fact.
The indexed colors are ordered that the (partially) transparent colors are at the beginning of the table. The SimpleTransparencyData now specifies the transparency of each of the indexed colors. Non-transparent colors are left out, as there are more colors than transparency values.
With that additional information it is easy to composite a single background color with the image.

Composite Chart + Objective C

I want to implement below chart like structure.
Explanation:
1. Each block should be clickable.
2. If the block is selected, it will be highlighted(i.e. Red block in figure).
I initially google for this but was unable to find. What should be "Drawing logic" corresponding to this with animation?Thanx in advance.
I think you need to use MCSegmentedControl.
You can get it from here.
Generally speaking, I'd have an image for the outline with a transparent middle, then dynamically create colored blocks behind it of the appropriate colors, with dynamic labels. The highlighting is a little tricky, but could be done with a set of image overlays. One could also try to shrink and expand fixed images for the bars/highlighting, but iPhone scales images poorly.
(Will it always be 4 blocks? There are a couple of other ways to manage it using fixed-size images overlaying each other.)
Maybe you should look into using CALayer for this?
U need to implement this type of logic using button. Just scale button width according to percentage.
And to make round rect button like appearance use the code below and don't forget to import quartz-core framework in class file.
And to scale first and last button as you need some overlap from nearby button.
btn.layer.cornerRadius = 8.0;
btn.layer.borderWidth = 0.5;
btn.layer.borderColor = [[UIColor blackColor] CGColor];

Iphonesdk boundries checking for coloring

im creating and app where user already have an image (with different objects) without colors, i have to check the object and then color with respected color with the touch on that objects. how should i do this. can anyone help me.
I would say that that is non-trivial. I can only give hints since I have not done such an app yet.
First, you need to convert the image into a CGImageRef, for example by doing [uiimage_object CGImage].
Next you need convert the CGImageRef into array of pixel colors. You can follow the tutorial at http://www.fiveminutes.eu/iphone-image-processing/ for sample code. But for your app you need to convert the array into two dimension based on image width and height.
Then, use the coordinate of the user touch to access the exact pixel color value from the array. Next you read off the color values of the surrounding pixels and determine if color is similar to the touched pixel or not (you might need to read some wikipedia articles etc on doing the color comparison). If the color is similar, change the color to the one you want. Recurse until the surrounding color is different (i.e. you hit the boundary).
When you are finished modifying the pixel color value array, you need to convert the array back into CGImageRef using CGImageCreate function. Then you convert back to UIImage using [UIImage imageWithCGImage:imageref].
Now you are on your own to implement the steps into code. It would be unreasonable if you expect me to code all that for you, wouldn't it?

UISlider to represent the color spectrum

I have a UISlider that is supposed to update the color of a textlabel. Now I want the user to be able to choose between all colors in the spectrum (sort of all anyway). I was thinking of using this UISlider to represent the colors and when dragging the slider the value/color changes.
I know the spectrum is not sequential like: [0,0,0]...[255,0,0]...[255,1,0]...[255,255,0] etc.
So: any tip on how I can implement this?
Color is at least a two or three dimensional selection. And a slider only provides a scalar output. If you want a smoothly changing selection using only a scalar parameter, you might try drawing a path line on some color chart (or a functional representation thereof) and select a point on that path parametrically.
Yes, color is a multidimensional value, but there are different ways to slice those dimensions. I think a hue, saturation, brightness constructor, rather than RGB, will give you exactly the effect you want. For example, often I will generate a random color with [UIColor colorWithHue:<random float in [0,1]> saturation:1.f brightness:1.f alpha:1.f].
Slide hue linearly from 0 to 1, with saturation and brightness fixed at the most legible (or whatever) values.