在 Xamarin.Forms 中使用 Font Awesome 5 Pro
像下面这样使用它...
(感谢SushiHangover的有用代码)
- 字体真棒 5 个品牌
*-- FontAwesome5BrandsRegular
- Font Awesome 5 Pro
*-- FontAwesome5ProLight
*-- FontAwesome5ProRegular
*-- FontAwesome5ProSolid
App.Xaml.cs
Current.Resources = new ResourceDictionary();
// Font awesome
Current.Resources["FontawesomeSolid"] = Device.RuntimePlatform == Device.iOS ? "Font Awesome 5 Pro" : "fa-solid-900.ttf#Font Awesome 5 Pro";
Current.Resources["FontawesomeRegular"] = Device.RuntimePlatform == Device.iOS ? "FontAwesome5Regular" : "fa-regular-400.ttf#Font Awesome 5 Pro";
Current.Resources["FontawesomeLight"] = Device.RuntimePlatform == Device.iOS ? "FontAwesome5ProLight" : "fa-light-300.ttf#Font Awesome 5 Pro";
Current.Resources["FontawesomeBrands"] = Device.RuntimePlatform == Device.iOS ? "FontAwesome5ProBrands" : "fa-brands-400.ttf#fFont Awesome 5 Pro";
Current.Resources.Add("ShareIconLabel", new Style(typeof(Label))
{
Setters =
{
new Setter { Property = Label.TextColorProperty, Value = Color.White},
new Setter { Property = View.HorizontalOptionsProperty, Value = LayoutOptions.End},
new Setter { Property = View.VerticalOptionsProperty, Value = LayoutOptions.Center},
new Setter { Property = AbsoluteLayout.LayoutBoundsProperty, Value = new Rectangle (0.90, 0.5, 0.2, 1)},
new Setter { Property = AbsoluteLayout.LayoutFlagsProperty, Value = AbsoluteLayoutFlags.All},
new Setter { Property = Label.FontSizeProperty, Value = 30},
new Setter { Property = Label.FontFamilyProperty, Value = Current.Resources["FontawesomeLight"] },
new Setter { Property = Label.TextProperty, Value = "\uf1e0" } // Share Icon
}
});
MySharePage.Xaml
<AbsoluteLayout
AbsoluteLayout.LayoutBounds="0,1,1,0.07"
AbsoluteLayout.LayoutFlags="All"
BackgroundColor="{x:Static localColors:Constants.MyOrange} ">
<Label
Style="{StaticResource ShareIconLabel}">
<!--<Label.GestureRecognizers>
<TapGestureRecognizer
Tapped="OnSocialShareClicked" />
</Label.GestureRecognizers>-->
</Label>
</AbsoluteLayout>