15

I'd like to add some icons in my app especially in listviews using custom cell and specify the color to be rendered. I don't want to edit each image in Photoshop; I want to apply an overlay color at runtime.

Is that possible with a custom renderer?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
dsmyrnaios
  • 325
  • 1
  • 4
  • 12
  • Why don't you put a `Grid` or something similar on top which you give a `BackgroundColor` and a `Opacity`? – Gerald Versluis Jun 16 '16 at 13:41
  • What have you tried? See [how to ask](http://stackoverflow.com/help/how-to-ask) and create a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – tmthydvnprt Jun 16 '16 at 13:41

2 Answers2

21

No it is not possible through standard Image class provided in Xamarin.Forms.

But you can use this amazing IconView custom renderer created by this guy. I use it all the time it is amazing.

IconView for Xamarin Forms

Usage

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="IconApp.MyPage"
             xmlns:controls="clr-namespace:IconApp;assembly=IconApp">
  <controls:IconView Source="monkey"
                     Foreground="Red"
                     WidthRequest="100"
                     HeightRequest="100"
                     HorizontalOptions="Center"
                     VerticalOptions="Center" />
</ContentPage>

Just specify the Foreground="Red" property color

enter image description here

George Papadakis
  • 1,273
  • 13
  • 22
2

Now We got another way with Xamarin.CommunityToolkit. We can use its IconTintColorEffect.TintColor for changing Tint Color or Overlay of an Image.

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
         x:Class="MyLittleApp.MainPage">
    <StackLayout>
        <Image Source="monkey" xct:IconTintColorEffect.TintColor="Red" />
    </StackLayout>
</ContentPage>

Xamarin.CommunityToolkit is handy and provides lot of features such as Shadows on any View, EventToCommandBehavior for MVVMifying lot of Events and Controls, it also has additional Converters, Extensions, Helpers, and Views that are not available in builtin Xamarin Forms yet.

Refer for more Documentation

Junaid Pathan
  • 3,850
  • 1
  • 25
  • 47
guyhuang
  • 43
  • 7