tags:

views:

74

answers:

3

I need to display a image view that is filled with violet color picture as shown belowalt text, but there us no UIColor color violet for this.

How can i display it?

+1  A: 

You can use:

[UIColor colorWithRed:0.5 green:0.0 blue:1 alpha:1.0]

to define a custom UIColor with values for red, green and blue, and set it to the background color of your ImageView:

imageView.backgroundColor = [UIColor colorWithRed:0.5 green:0.0 blue:1 alpha:1.0];

Take a look at this question regarding adding a border to the view.

EDIT (Question clarified somewhat)

It looks like you're trying to display an image that has a portion coloured at runtime.

To do this, create the image as a png, and leave the parts you want to be filled with the color transparent. You can then set the background color of the UIImageView to the violet approximation, and set the image property to the image you created.

Note that Violet is outside the color gamut of the RGB colour space, so you'll need to find the RGB values of the color you want. Also note this function takes values between 0 and 1 rather than 0 and 255.

Mr. Matt
it shows pink color not violet color
MaheshBabu
violet is outside the color gamut of the RGB color space, thought there are some approximations on this article: http://en.wikipedia.org/wiki/Violet_(color)
Mr. Matt
thanks a lot MR.Matt it works fine
MaheshBabu
A: 

try this if earlier one not worked

something got wrong on my side,

imgView.backgroundColor = [UIColor colorWithRed:0.6 green:0.2 blue:1 alpha:1];

viv
How does this answer any part of the question?
Mr. Matt
Theres no `setBackground` property for imageview. Mahesh how can you tick the wrong answers as correct. Please tick correct answer.
Suriya
this one should work imgView.backgroundColor = [UIColor colorWithRed:0.6 green:0.2 blue:1 alpha:1];
viv
Please refer to my answer - Violet is outside the color gamut of the RGB color space.
Mr. Matt
A: 

My answer is same as Mr. Matt but the only problem with matts answer is as per MAHESHBABU it gives pink color. So now please try below code for your answer

imageView.backgroundColor = [UIColor colorWithRed:144.0/255.0 green:0.0/255.0 blue:255.0/255.0 alpha:1.0];

This is surely gonna give you correct color.

hAPPY cODING...

Suriya
atleast comment the reason for downVote. So dat i can Know the problem in my answer as i have tried the answer practically and its not having any problem.
Suriya
it shows white color not violet color
MaheshBabu
I have checked it again and its giving voilet color. Check it again may be you have done some mistake in code.
Suriya