user7752337
user7752337

Reputation:

Xamarin iOS Image Tint Color

I want to use an template image which is black and use the tintColor of this image to set the color and to have only one image.

Then I put template image in asset And I try to change the color by :

object.TintColor = UIColor.Blue;

But it doesn't work, it still black

Can someone help me please ?

Thanks

Upvotes: 4

Views: 3640

Answers (1)

MilanG
MilanG

Reputation: 2604

You must set the image rendering mode to AlwaysTemplate in order to have the TintColor affect your UIImage, otherwise it will display image as is. It helps control the color of Image to any color you wish to set, with having a single image in Resources or xcassets.

Following Code should Help you.

imgViewObject.Image = imgViewObject.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
imgViewObject.TintColor = UIColor.Blue;

We can also set Rendering Mode from xcassets as shown in following image:

xcassets Render As

For more details about Working with Template Images

Upvotes: 12

Related Questions