Xamarin表示iOS和Android非常轻量级(瘦)字体

问题描述 投票:0回答:2

我的应用程序中有一个大尺寸标签,我已经实现了这一点,因此标签的字体重量较小:

<?xml version="1.0" encoding="utf-8"?>
<Label xmlns="http://xamarin.com/schemas/2014/forms" 
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
       xmlns:local="clr-namespace:Japanese;assembly=J" 
       x:Class="J.Templates.WordLabel" >
    <Label.FontFamily>
        <OnPlatform x:TypeArguments="x:String" Android="sans-serif-thin" iOS=".SFUIText-Light" />
    </Label.FontFamily>
</Label>

有谁知道如何在Android和iOS上实现具有更小权重的字体?

xamarin xamarin.forms
2个回答
1
投票

您可以根据自己的要求使用Google字体。来自here

现在将字体添加到Android(Assets)设置属性为AndroidAssets,将iOS(资源)设置属性添加为BundleResource。

1)将以下代码添加到App.xaml并提供字体名称(在我的案例中为OpenSans-Regular)。

 <Application.Resources>
        <ResourceDictionary>
            <OnPlatform x:Key="fontFamilyOpenSansRegular" x:TypeArguments="x:String" iOS="OpenSans-Regular" Android="OpenSans-Regular.ttf#OpenSans-Regular" /> 
</ResourceDictionary>
    </Application.Resources>

2)使用DynamicResource调用如下字体。

<Label Text="Test" TextColor="#1db4d9" HorizontalOptions="FillAndExpand" HorizontalTextAlignment="Center" FontFamily="{DynamicResource fontFamilyOpenSansRegular}">

它完成了。如果它适合您,请告诉我。


0
投票

您需要为iOS做的另一件事是在Info.plist中添加一个条目。

enter image description here

原始条目是:

<key>UIAppFonts</key>
<array>
    <string>fontawesome.ttf</string>
    <string>Signika-Light.ttf</string>
    <string>ionicons.ttf</string>
</array>
© www.soinside.com 2019 - 2024. All rights reserved.