Man*_*nsa 4 xaml xamarin font-awesome xamarin.forms
我想知道我是否在这里遗漏了一些东西。
在 iOS 的 xaml 中使用 FontAwesome 时,它的工作原理如下:
<Button Text="" HeightRequest="100" BackgroundColor="DarkRed" TextColor="White" FontSize="36">
<Button.FontFamily>
<OnPlatform x:TypeArguments="x:String" Android="fa-regular-400.ttf#Font Awesome 5 Free Regular" iOS="Font Awesome 5 Free" WinPhone="Assets/fa-regular-400.ttf#Font Awesome 5 Free" />
</Button.FontFamily>
</Button>
Run Code Online (Sandbox Code Playgroud)
但是在页面后面的代码中执行此操作时,我没有得到图标而是它的 unicode ;
这是我的代码背后的代码:
var newBtn = new Button()
{
Text = "",
HeightRequest = 100,
BackgroundColor = Color.DarkRed,
TextColor = Color.White,
FontSize = 36
};
newBtn.FontFamily = Device.RuntimePlatform == Device.iOS ? "Font Awesome 5 Free" : null;
Run Code Online (Sandbox Code Playgroud)