如何在Xamarin.Forms(以编程方式)中使用ToolBarItems的本机平台图标? [英] How to use native platform icons for ToolBarItems in Xamarin.Forms (programmatically)?

查看:1171
本文介绍了如何在Xamarin.Forms(以编程方式)中使用ToolBarItems的本机平台图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有什么:

我有一个 Xamarin.Forms 应用iOS上的 ToolBar ActionBar ,iOS上的导航栏 )。在 ToolBar 中,我有 ToolBarItem 来删除内容。

I have a Xamarin.Forms app with a ToolBar (ActionBar on Android, Navigation Bar on iOS). Within the ToolBar I have a ToolBarItem to delete something.

我想要的是什么:

对于上面提到的 ToolBarItem ,我想使用原生平台图标(垃圾桶)。

For the ToolBarItem mentioned above I want to use the native platform icons (f.e. a trash can).

我的问题:

实现这一目标的正确方法是什么?似乎唯一的方法是添加和加载单独的png文件,如上所述这里。对于Android来说,这不是什么大问题,我可以从谷歌的开发者页面正式下载图标文件。对于iOS,这是不可能的。

What is the proper way to achieve this? It seems that the only way to do this is to add and load separate png-files as described here. For Android this is not such a big deal I can officially download the icon files from Google's developer page. For iOS this is not possible.

推荐答案

目前看起来几乎不可能覆盖。查看 ToolbarRenderer 的来源,您可以看到 UpdateItems 方法。这假设所有工具栏项都是 ToolbarItem 类型,并且它不会为它们调用自定义渲染器,而是直接调用转换<$ c $的扩展方法c> ToolbarItem 进入 UIBarButtonItem 的值包含 UIImage

Currently this looks to be almost impossible to override. Looking at the source for ToolbarRenderer you can see the UpdateItems method. This assumes that all of the toolbar items are of type ToolbarItem and it does not invoke a custom renderer for them, instead calling through directly to an extension method that converts ToolbarItem values into UIBarButtonItems containing a UIImage.

这篇关于如何在Xamarin.Forms(以编程方式)中使用ToolBarItems的本机平台图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆