Created
June 16, 2022 12:27
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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