Xamarin 中带有普通文本的 FontAwesome 图标

FontAwesome icon with normal text in Xamarin

我想在我的 Xamarin 应用程序中制作一个带有小图标(来自 FontAwesome) 文本的按钮。我知道我可以制作一个按钮,但问题是我需要两种字体(文本的标准字体和图标的 FontAwesome)。有没有人碰巧知道我该怎么做,或者是否有其他方法可以实现我想要的?

谢谢!

正如json提到的,我只是做了一个简单的实现。

创建一个新的 class 继承自 Label,设置 FormattedText 组合字符串(标准和图标),并在其上添加点击手势。

 public class MyLabel : Label
    {
        public delegate void MyHandler(object sender, EventArgs e);
        public event MyHandler myEvent;

        public MyLabel(string _myIcon, string _myText)
        {

            //build the UI
            FormattedString text = new FormattedString();
            text.Spans.Add(new Span { Text = _myIcon ,FontFamily= "FontAwesome5Free-Regular" });
            text.Spans.Add(new Span { Text = _myText, TextColor = Color.Red ,BackgroundColor = Color.Blue });
            FormattedText = text;

            //tap event
            TapGestureRecognizer tap = new TapGestureRecognizer();
            tap.Tapped += (sender,e) => {
                myEvent(sender,e);
            };
        }
    }

用法

MyLabel label = new MyLabel("", "test");
label.myEvent += (sener,e) =>
{
    //do something when tapping 
};
Content = label;

如何在Xamarin.Forms中整合FontAwesome,参考

https://montemagno.com/xamarin-forms-custom-fonts-everywhere/.