【问题标题】:Add overlay color to an image using Xamarin.Forms使用 Xamarin.Forms 向图像添加叠加颜色
【发布时间】:2016-10-18 01:47:58
【问题描述】:

我想在我的应用程序中添加一些图标,尤其是在使用自定义单元格的列表视图中,并指定要呈现的颜色。 我不想在 Photoshop 中编辑每个图像;我想在运行时应用叠加颜色。

自定义渲染器可以做到吗?

【问题讨论】:

标签: image xamarin.forms


【解决方案1】:

不,通过 Xamarin.Forms 中提供的标准 Image 类是不可能的。

但是你可以使用这个家伙创建的这个惊人的IconView 自定义渲染器。我一直在使用它,它很棒。

IconView for Xamarin Forms

用法

<?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>

只需指定Foreground="Red" 属性颜色

【讨论】:

  • 超级棒。谢谢男人:)
  • 它在图像上完美运行。是否可以使其在图像按钮上工作?
【解决方案2】:

现在我们使用 Xamarin.CommunityToolkit 获得了另一种方法。我们可以使用它的IconTintColorEffect.TintColor 来更改图像的色调颜色或叠加层。

<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 很方便,并提供许多功能,例如任何视图上的阴影,EventToCommandBehavior 用于 MVVMifying 大量事件和控件,它还具有额外的转换器、扩展、帮助程序和视图尚未在内置 Xamarin 表单中提供。

Refer for more Documentation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-07
    • 2016-08-09
    • 2011-03-03
    相关资源
    最近更新 更多