11

I have a table view, I have addeed image as subview for header, but that image is shown with bagckground white color,how to set transparency for image.

TIA

Feroz
  • 699
  • 5
  • 17
  • 25

4 Answers4

14

For this you have to set alpha of your UIImageView

Your_ImageView.alpha = 0.6;

You can also do it in your xib file

superGokuN
  • 1,399
  • 13
  • 28
  • I am adding image programatically. By the way setting alpha low hides the visibility of image also.. Any Idea? – Feroz Aug 06 '12 at 08:59
  • if you are adding it programatically then you can use the line Your_ImageView.alpha = 0.6; and make sure the image you are using must have transparent backgroung – superGokuN Aug 06 '12 at 09:01
  • @naveen this will set the transparency for the *full* image, the OP is looking to make the background transparent. – James Aug 06 '12 at 09:02
  • @James For this you have to make an image with transparent background and your question should be image with transparent background not the transparent image – superGokuN Aug 06 '12 at 09:04
  • @James, May be my question is wrong I want transparent background only, sorry for that. I have transparent background image only still I need to do anything in code. ? – Feroz Aug 06 '12 at 09:12
  • @james try giving your imageview background color as clearcolor this may help you – superGokuN Aug 06 '12 at 09:19
  • @naveen `For this you have to make an image with transparent background` - not true, you can use image masking see my answer. – James Aug 06 '12 at 09:32
  • @James thanks for that..as a beginner i have many things to learn :) and sorry for misunderstanding :( – superGokuN Aug 06 '12 at 09:38
2

Assuming the name of your view is myTransparentSubView:

[myTransparentSubView setBackgroundColor:[UIColor clearColor]];

If you are using the Interface Builder then set the background Color property accordingly within IB.

Hermann Klecker
  • 14,039
  • 5
  • 48
  • 71
0

The simplest solution is to infact to create an image with a transparent background, however, you can use an Image Mask to get the desired effect.

There is already an example of this here.

Community
  • 1
  • 1
James
  • 80,725
  • 18
  • 167
  • 237
-1

Use image Preview in MAC

Start with a png file.

You have to go to View > Show Edit Toolbar.

Then widen the window so that you can see all of the icons.

Then click the icon that looks like a magic wand.

And then click and drag on the color you want to erase.