如何在XAML/C中显示字体真棒字形#
我已经在Visual Studio中尝试了很多东西,但仍然无法显示字形。如何在XAML/C中显示字体真棒字形#
- 我需要添加一个NuGet包吗?哪一个?
- 我需要'使用...'吗?在C#中?
- 我需要XAML中的'xmlns:...'吗?
- 我应该用“标签”来显示吗?
我知道在HTML中,你只是添加一个类到你的元素。但我沉迷于XAML。 (它是跨平台的,对吗?)
这应该是一件简单的事情,但我不能得到任何函数的答案。如果您可以做到这一点并回答所有问题,请提供答案。
Xamarin.Forms有一个正确的plugin。这个插件不仅有FontAwesome Font。
根据this example in github你必须做到以下几点:
<StackLayout Orientation="Horizontal">
<iconize:IconLabel FontSize="20" Text="{Binding Key}" TextColor="Green" VerticalTextAlignment="Center" />
</StackLayout>
[更新]
在从user3247130请求我留下完整的示例:
从Visual Studio或Xamarin Studio中,安装以下软件包:
- Xam.Plugin.Iconize
- Xam.Plugin.Iconize.FontSwesome
- Xam.FormsPlugin.Iconize
在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" />
[UPDATE 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
到anoother文件夹Assets
文件夹
最后复制iconize-fontawesome.ttf文件(你不应该改变他们的名字)。
此外,您必须在资产在UWP项目中添加一个字体文件夹文件夹,然后粘贴相同的ttf文件
这不是Android或iOS上需要它仅仅是一个在UWP平台的问题
请阅读更新.... –
您可以创建一个[gist](https://gist.github.com/)以便能够查看您的源代码? –
您要部署哪个平台? –
请学会使用谷歌 - https://github.com/jsmarcus/Xamarin.Plugins/tree/master/Iconize – Jason
@ Flot2011我似乎无法得到这个工作。每当我有'FontAwsome ...'时,仍然会得到一个红色下划线。什么秘密? – user3247130
@Jason这是否也形成UWP? – user3247130