【问题标题】:Xamarin Forms iOS and Android very light weight (thin) fontXamarin Forms iOS 和 Android 非常轻量(细)字体
【发布时间】:2019-08-31 22:38:26
【问题描述】:

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

<?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


【解决方案1】:

您可以根据需要使用 Google 字体。来自here

现在将字体添加到 Android(Assets) 设置属性为 AndroidAssets 和 iOS(Resource) 设置属性为 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}">

它完成了。 让我知道它是否适合您。

【讨论】:

    【解决方案2】:

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

    原始条目是:

    <key>UIAppFonts</key>
    <array>
        <string>fontawesome.ttf</string>
        <string>Signika-Light.ttf</string>
        <string>ionicons.ttf</string>
    </array>
    

    【讨论】:

    • 如果使用系统字体我还需要这样做吗?
    • 我想是这样 - 如果它是您添加到 Resources 的字体。
    猜你喜欢
    • 1970-01-01
    • 2020-04-13
    • 1970-01-01
    • 2011-11-13
    • 2021-11-14
    • 2015-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多