0

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?

Mahesh Babu
  • 3,395
  • 9
  • 48
  • 97
  • So you're actually trying to display an image filled with a custom color? – Codebeef Sep 10 '10 at 12:15
  • ya i need this custom color RGB value for this i used [UIColor colorWithRed:127.0 green:0.0 blue:255.0 alpha:1.0] it displayed another color – Mahesh Babu Sep 10 '10 at 12:28

3 Answers3

1

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.

Community
  • 1
  • 1
Codebeef
  • 43,508
  • 23
  • 86
  • 119
  • 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) – Codebeef Sep 10 '10 at 11:26
-1

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...

Suresh Varma
  • 9,750
  • 1
  • 60
  • 91
  • 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. – Suresh Varma Sep 14 '10 at 09:58
  • I have checked it again and its giving voilet color. Check it again may be you have done some mistake in code. – Suresh Varma Sep 22 '10 at 11:30
-2

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];
Suresh Varma
  • 9,750
  • 1
  • 60
  • 91
viv
  • 6,158
  • 6
  • 39
  • 54