Skip to content

Instantly share code, notes, and snippets.

@vhugogarcia
Created June 16, 2022 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vhugogarcia/ededa0e18eb65cb330423d1f79cc103d to your computer and use it in GitHub Desktop.
Save vhugogarcia/ededa0e18eb65cb330423d1f79cc103d to your computer and use it in GitHub Desktop.
How to tint an image in .NET MAUI for iOS and Android using Handlers
using System.Diagnostics;
using Microsoft.Maui.Platform;
namespace Demo.Handlers;
public partial class ImageTinted : Image
{
public ImageTinted()
{
ModifyImage();
}
void ModifyImage()
{
Microsoft.Maui.Handlers.ImageHandler.Mapper.AppendToMapping("TintColor", (handler, view) =>
{
if (view is ImageTinted)
{
#if ANDROID
handler.PlatformView.SetColorFilter(Colors.White.ToPlatform());
#elif IOS
handler.PlatformView.Image = handler.PlatformView.Image.ImageWithRenderingMode(UIKit.UIImageRenderingMode.AlwaysTemplate);
handler.PlatformView.TintColor = Colors.White.ToPlatform();
#endif
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment