Curious Programmer
Curious Programmer

Reputation: 433

Swift changes colour of image when loaded

I have a swift playground in Xcode 7.3.1 and I am trying to load in this image Mouth into my program using let mouth = UIImage(named: "happy-mouth"). When the program runs the swift compiler returns the image like this...

enter image description here

Why does the swift playground change the colour of the image to a maroon colour instead of a peach colour?

Things I have tried

Upvotes: 0

Views: 209

Answers (2)

Alonso Urbano
Alonso Urbano

Reputation: 2264

This is a common issue with transparent images. As they are usually shown in a UIImageView which inherits the background color from its parent view (superview) which is usually white, you don't get to notice that.

Instead of modifying the image, put it in a UIImageView and set the background color (of the UIImageView) to white.

Upvotes: 1

Curious Programmer
Curious Programmer

Reputation: 433

The issue is most likely that the image you have is partly transparent, because of that it mixes with the dark colour behind it changing the way it appears compared to how it appears on a white background. To fix this go back into your image editor (e.g. sketch, photoshop, illustrator) and make the colour opaque.

Upvotes: 0

Related Questions