簡體   English   中英

Xamarin.Forms:如何在C#代碼中使用自定義字體

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM