JZonker JZonker - 4 years ago 207
Swift Question

How to make an image without a background in Xcode

My current method for putting an image on a view controller is to place an image view and select the image I want to be displayed. How can I make it so that this image does not have a background? Basically, I want to make a "png" type image on my view controller.

enter image description here

You can see in the image provided how the background of my image is a white box. I want an image basically to conform to the shape of the actual picture and not have a boxy background. I apologize as I am sure this info is available online, but thus far I have been unlucky. Thanks so much for any help or guidance.

Answer Source

You can control the background color and opacity of your UIImageView that is holding your image by adding this row

imgView.backgroundColor = UIColor(red: 33.0, green: 33.0, blue: 33.0, alpha: 0.5)

And if you want more transparency, you could change the alpha value. I don´t think it´s possible to trim an image background color if the image already has a background.

In your case wouldn't it just be easier for you to remove the backgrounds of your images (in Photoshop etc...) and then add them to your views? In that case you would have the image without a background color and then you don´t have to do anything with the background color of your UIImageView.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download