![](/img/trans.png)
[英]How to use value of a C# variable in XAML in Xamarin.Forms?
[英]Xamarin.Forms: How to use custom Fonts in C# Code
我想在Xamarin.Forms
應用程序中使用一些自定義字體(.ttf)
。 我在兩個項目(Android / iOS)中都添加了兩種字體:
現在,在XAML-Page
,我將字體添加到ResourceDictionary
。 也可以使用Fonts,但僅在XAML-File
:
<Label Text="Test" FontFamily="{StaticResource FONT}" FontSize="Medium"/>
但是如何在C#
代碼中使用此字體?
Device.RuntimePlatform屬性可用於在每個平台上設置不同的字體名稱。
if (Device.RuntimePlatform == Device.iOS)
{
label.FontFamily = "xxx.ttf";
}
else if (Device.RuntimePlatform == Device.Android)
{
label.FontFamily = "xxx.ttf#xxx";
}
else
{
label.FontFamily = "Assets/Fonts/xxx.ttf#xxx";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.