如何在项目中使用Font Awesome图标作为ImageButton的图标 [英] How to use Font Awesome icons in project as an icon of ImageButton
问题描述
我在实现如何在Xamarin应用程序中使用Font Awesome图标时遇到问题,我想将它与 ImageButton
作为图标一起使用.而且我发现的大多数教程都没有帮助我理解它的工作原理.
如 Embedded Resource . 有关图标代码的列表,请查看 FontAwesome代码. 如果您想将其与按钮之类的点击功能一起使用,则可以将标签与 最好使用带有 您还可以定义一个具有 我邀请您关注此视频教程并查看 I am having a problem to realize how to use Font Awesome icons in my Xamarin application, I want to use it with As explained in Microsoft Documentation:
For the list of icons code take a look at FontAwesome codes. If you want to use it with click capabilities like a button, then you can use a label with GestureRecognizers:
Even better use an You can also define a static class having I invite you to follow this video tutorial and check out this GitHub Page which generate the static c# class for you starting from a font glyph file that you submit. 这篇关于如何在项目中使用Font Awesome图标作为ImageButton的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! AssemblyInfo.cs
或 App.xaml.cs
中 [程序集:ExportFont("file-name.ttf",Alias ="FontAwesome")]
< Label FontFamily ="FontAwesome";文本="/>
更新
FontImageSource
属性而不是标签的 ImageButton
,您具有按钮的单击功能,而且我发现有趣的是,您可以更改颜色字形图标,根据选定主题进行硬编码或动态编码>,这是一个示例:
< ImageButton>< ImageButton.Source>< FontImageSource FontFamily =" FontAwesome"字形="{x:静态字体:IconFont.AddressBook}"颜色=" {AppThemeBinding Dark =白色,浅=黑}"//;</ImageButton.Source></ImageButton>
const string
属性的静态类,每个类都具有与图标字形相对应的代码作为值,并以这种方式的描述作为名称,您只需要提供描述,而不是像我对 Glyph =" {x:Static fonts:IconFont.AddressBook}}
所做的那样,它将看起来像这样:
静态类IconFont{public const string Ad ="\ uf641";公共常量字符串AddressBook ="\ uf2b9";...}
ImageButton
as icon. And most tutorials I found didn't help me understand how it works.
.ttf
(or .otf).AssemblyInfo.cs
or App.xaml.cs
:[assembly: ExportFont("file-name.ttf", Alias = "FontAwesome")]
<Label FontFamily="FontAwesome" Text=""/>
<Label FontFamily="FontAwesome" Text="">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
</Label.GestureRecognizers>
</Label>
UPDATE
ImageButton
with a FontImageSource
property instead of a label, you have click capabilities of a button also I found interesting that you can change the color of your glyph icon, weather hard-coded or dynamically depending on the selected theme, here is an example:<ImageButton>
<ImageButton.Source>
<FontImageSource FontFamily="FontAwesome"
Glyph="{x:Static fonts:IconFont.AddressBook}"
Color="{AppThemeBinding Dark=White,
Light=Black}"/>
</ImageButton.Source>
</ImageButton>
const string
properties, each one having as value the code corresponding to an icon glyph and as name a description of it that way you will need to provide only the description instead of the code like I did with Glyph="{x:Static fonts:IconFont.AddressBook}"
, it will looks something like this: static class IconFont
{
public const string Ad = "\uf641";
public const string AddressBook = "\uf2b9";
...
}