Reputation: 6801
I am having problems with a png
image, that gets wrong colors on iOS compared to the actual image.
It does not matter how I am using the image, it always gets the wrong colors. I have tried on UIButton
and UIImageView
and it gives the same result.
It is a very standard use of a UIImage
:
UIImage* greenButtonImg = [UIImage imageNamed:@"btn_green"];
UIImageView* testView = [[UIImageView alloc] initWithImage:greenButtonImg];
[self.view addSubview:testView];
The second image is how it looks on iOS and the first button is how it looks on my Mac (Finder and Photoshop):
As you can see the second button has a different green color. This is happening all over the app where am using this picture. It happens in the Simulator and on a iPhone 5.
What can cause this issue? Can this be caused by settings in Photoshop, where the image was created?
Upvotes: 5
Views: 1071
Reputation: 6394
In iOS 7.0, the image is colored with the toolbar’s tintColor
.
In iOS 7.0, all subclasses of UIView
derive their behavior for tintColor
from the base class.
By default, an image (UIImage
) is created with UIImageRenderingModeAutomatic
.
If you have UIImageRenderingModeAutomatic
set on your image, it will be treated as template or original based on its context.
Certain UIKit
elements—including navigation bars, tab bars, toolbars, segmented controls—automatically treat their foreground images as templates, although their background images are treated as original.
Other elements—such as image views and web views—treat their images as originals. If you want your image to always be treated as a template regardless of context, set UIImageRenderingModeAlwaysTemplate
.
If you want your image to always be treated as original, set UIImageRenderingModeAlwaysOriginal
.
Refer Template Images for more info.
Upvotes: 1
Reputation: 6801
As Jeff wrote in a comment it was a problem with the RGB Profiles.
I managed to fix the problem by converting the color profile in Photoshop:
Edit -> Convert to Profile... -> Set profile to "Apple RGB"
Upvotes: 3