我在Visual Studio中尝试了很多东西,但我仍然无法显示字形。
我知道在HTML中,您只需在元素中添加一个类。但我被XAML困扰了。 (这是跨平台的,对吧?)
这应该是一件简单的事情,但我无法得到任何功能的答案。如果你能做到并回答所有问题,请提供答案。
答案 0 :(得分:2)
Xamarin.Forms有一个正确的plugin。这个插件不仅有FontAwesome Font。
根据this example in github,您必须执行以下操作:
<StackLayout Orientation="Horizontal">
<iconize:IconLabel FontSize="20" Text="{Binding Key}" TextColor="Green" VerticalTextAlignment="Center" />
</StackLayout>
<强> [UPDATE] 强>
根据user3247130的要求,我留下完整的例子:
从Visual Studio或Xamarin Studio安装以下软件包:
在Android项目中,MainActivity
类,OnCreate()方法添加:
FormsPlugin.Iconize.Droid.IconControls.Init(Resource.Id.toolbar);
Plugin.Iconize.Iconize.With(new Plugin.Iconize.Fonts.FontAwesomeModule());
在iOS项目中,AppDelegate
类,FinishedLaunching()方法,添加类似的行:
FormsPlugin.Iconize.iOS.IconControls.Init();
Plugin.Iconize.Iconize.With(new Plugin.Iconize.Fonts.FontAwesomeModule());
另外,在iOS项目中,info.plist添加
<key>UIAppFonts</key>
<array>
<string>iconize-fontawesome.ttf</string>
</array>
现在,在你的XAML
工具栏中,在标签中添加
<ContentPage ...
xmlns:iconize="clr-namespace:FormsPlugin.Iconize;assembly=FormsPlugin.Iconize">
和
<iconize:IconLabel Text="fa-search" />
[更新2]
此插件在UWP平台上存在问题。 要在UWP平台上运行此插件,请执行以下步骤:
首先,在Plugin.Iconize.FontAwesome.UWP
%userprofile%\.nuget\packages\xam.plugin.iconize.fontawesome\2.0.0.29-beta\lib\UAP10\
的文件夹
其次,在Assets
文件夹
Plugin.Iconize.FontAwesome.UWP
的文件夹
第三个创建另一个名为Fonts
的文件夹到Assets
文件夹
最后复制iconize-fontawesome.ttf文件(你不应该更改他们的名字)。
此外,您必须在UWP项目的资产文件夹中添加字体文件夹,然后粘贴相同的ttf文件
这在Android或iOS上不是必需的,它只是UWP平台的一个问题
答案 1 :(得分:0)
尝试Plugin.Glypher,它具有Font Awesome 5 Free / Pro和WeatherIcons支持。
xmlns:fontAwesome5Free="clr-namespace:Plugin.Glypher.FontAwesome5Free;assembly=Plugin.Glypher.FontAwesome5Free"
xmlns:glypher="clr-namespace:Plugin.Glypher;assembly=Plugin.Glypher"
<Label glypher:FontGlyph.Glyph="{x:Static fontAwesome5Free:GlyphList.Fab_Bluetooth}"
FontSize="Large"
TextColor="CornflowerBlue" />
<Button glypher:FontGlyph.Glyph="{x:Static fontAwesome5Free:GlyphList.Fab_Bitcoin}"
FontSize="Large"
TextColor="IndianRed" />
<Image>
<Image.Source>
<FontImageSource Size="32"
Color="Orange"
glypher:FontGlyph.Glyph="{x:Static fontAwesome5Free:GlyphList.Far_Bell_Slash}" />
</Image.Source>
</Image>
全部使用共享代码。但这取决于Xamarin.Forms(> = 3.6.0.344457)