【问题标题】:Xamarin IOs, What are the string values to pass into UIFontMetrics.GetMetrics method for the textStyle parameter?Xamarin IO,要传递给 textStyle 参数的 UIFontMetrics.GetMetrics 方法的字符串值是什么?
【发布时间】:2018-11-02 08:19:06
【问题描述】:

我有一个 Xamarin.IOs 项目。我需要在我的应用程序中使用动态字体。

我已经跟随this tutorial 这样做了。我猜这个教程很快就出来了。而对于代码段,

label.Font = UIFontMetrics(forTextStyle: .title1).ScaledFont(for: customFont)

在教程中,等效的 Xamarin.IOs C# 代码是,

label.Font = UIFontMetrics.GetMetrics(textStyle: <string_value>).GetScaledFont(customFont);

但是对于&lt;string_value&gt;textStyle,我可以使用哪些值?

我试过了,

  • "title 1"
  • "title1"
  • ".title1"
  • ".title 1"
  • "UIFontTextStyleTitle1"
  • "PreferredTitle1"

但没有帮助。

UIFontMetrics.GetMetrics() 接受哪些字符串值?

【问题讨论】:

    标签: ios xamarin xamarin.ios dynamictype


    【解决方案1】:

    有两种方法可以做到这一点,

    方式一:

    UIFontMetrics.GetMetrics(UIFontDescriptor.PreferredTitle1.TextStyle).GetScaledFont(customFont);
    

    文本样式的字符串值可以取自UIFontDescriptor文本样式属性的TextStyle属性,

    UIFontDescriptor.PreferredTitle1.TextStyle
    

    方式二:

    UIFontMetrics.GetMetrics(UIFontTextStyle.Title1.GetConstant()).GetScaledFont(customFont);
    

    文本样式的字符串值可以取自UIFontTextStyle文本样式属性的GetConstant()扩展方法,

    UIFontTextStyle.Title1.GetConstant()
    

    其中一个比直接输入字符串值要好得多?

    【讨论】:

    • 我很惊讶 Xamarin 没有为此创建常量。叹息,Xamarin。
    猜你喜欢
    • 2018-01-23
    • 2020-05-11
    • 1970-01-01
    • 2011-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多