在Xamarin表单中使用自定义字体 [英] Use custom fonts in xamarin forms

查看:263
本文介绍了在Xamarin表单中使用自定义字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在便携式文件夹(不是iOS和android)的xamarinforms的xaml文件中使用自定义字体,该字体可获取所有此平台的输出.

I want to use custom font in xaml file in xamarinforms on the portable folder(not iOS and android) that get an output for all of this platform.

推荐答案

  1. 按照说明在此处.
  2. 创建一种可以在您的平台上反映的字体样式,例如:

  1. Add fonts into your platforms as explained here.
  2. Create a font style that reflects on your platform like:

    <OnPlatform x:Key="NormalFont" x:TypeArguments="x:String"
                iOS="Montserrat" Android="Montserrat"
                WinPhone="Assets/Fonts/Montserrat-Regular.ttf#Montserrat"/>

  • 与以下任何选项结合使用:

  • use it with any of below options:

    • 直接使用: <Label Text="test" FontFamily="{StaticResource NormalFont}"/>

    • Direct using : <Label Text="test" FontFamily="{StaticResource NormalFont}"/>

    使用匿名样式(会影响您应用中的所有标签)

    Using With anonymous style (that affects all labels in your app):

    <Style TargetType="Label">
        <Setter Property="FontFamily" Value="{StaticResource NormalFont}"/>
    </Style>
    

  • 与命名样式一起使用:

  • Use with named Style:

    <Style x:Key="TitleStyle" TargetType="Label">
        <Setter Property="FontFamily" Value="{StaticResource Boldfont}"/>
    </Style>
    
    <Label Text="Options" Style="{StaticResource TitleStyle}"/>
    

  • 这篇关于在Xamarin表单中使用自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆