Xamarin表单图标 [英] Xamarin Forms Icons
问题描述
我想知道如何在Xamarin Forms应用程序内实现图标.我想使用字形文字或超棒的字体.但是,我不知道如何在我的xaml/c#页面中实现它.
I'm wondering how I can implement icons inside my Xamarin Forms app. I want to use something like glyphicons or font awesome. However, I have no idea how to implement it into my xaml/c# pages.
理想情况下,我的目标是这样的:
Ideally, I am aiming for something like this:
如果有人可以提供代码来显示图标(如搜索栏或三行),那将是很好的.我可以将其格式化为漂亮的外观.我正在努力如何实际拉入图标!
If someone could provide the code to display an icon like the search bar or three lines, that would be great. I can format it to look pretty. I'm struggling with how to actually pull in the icon!
推荐答案
最简单的方法可能是使用 https://github.com/jsmarcus/Xamarin.Plugins
The easiest way may be is to use https://github.com/jsmarcus/Xamarin.Plugins
从Visual Studio或Xamarin Studio中,安装以下软件包:
From Visual Studio or Xamarin Studio, install the following packages:
- Xam.Plugin.Iconize
- Xam.Plugin.Iconize.FontAwesome
- Xam.FormsPlugin.Iconize
注意:如果需要,您可以安装Xam.Plugin.Iconize.Material以及许多其他类似的东西.
Note: you can install Xam.Plugin.Iconize.Material and many others similar if you want to.
在Android项目中,使用MainActivity类的OnCreate()方法添加
In the Android project, MainActivity class, OnCreate() method add
FormsPlugin.Iconize.Droid.IconControls.Init(Resource.Id.toolbar);
Plugin.Iconize.Iconize.With(new Plugin.Iconize.Fonts.FontAwesomeModule());
在iOS项目的AppDelegate类FinishedLaunching()方法中,添加相似的行
In the iOS project, AppDelegate class, FinishedLaunching() method, add similar lines
FormsPlugin.Iconize.iOS.IconControls.Init();
Plugin.Iconize.Iconize.With(new Plugin.Iconize.Fonts.FontAwesomeModule())
此外,在iOS项目中,添加info.plist
Also, in the iOS project, info.plist add
<key>UIAppFonts</key>
<array>
<string>iconize-fontawesome.ttf</string>
</array>
现在,在具有工具栏的XAML中,在标记中添加
Now, in your XAML where you have your toolbar, in tag, add
<ContentPage ...
xmlns:iconize="clr-namespace:FormsPlugin.Iconize;assembly=FormsPlugin.Iconize" ...
>
和
<ContentPage.ToolbarItems>
<iconize:IconToolbarItem Order="Primary" Clicked="..." Icon="fa-search" IconColor="White" />
</ContentPage.ToolbarItems>
这篇关于Xamarin表单图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!