【问题标题】:Custom font with dynamic type in interface builder界面生成器中具有动态类型的自定义字体
【发布时间】:2020-03-12 20:30:36
【问题描述】:

我的 Storyboard 中有几个视图,它们有 UILabels。这些标签设置为Automatically Adjusts Font,并使用BodyHeadline 等文本样式。

我知道有这样一种程序化方法: https://useyourloaf.com/blog/using-a-custom-font-with-dynamic-type/

let label = UILabel()
label.font = scaledFont.font(forTextStyle: textStyle)
label.adjustsFontForContentSizeCategory = true

但是,鉴于我已经布置了标签并设置了它们的文本样式,有没有办法在界面生成器中使用自定义字体 AND 文本样式?或者可能以某种方式覆盖他们的字体系列,同时尊重他们已经设置的文本样式?

【问题讨论】:

    标签: swift xcode interface-builder


    【解决方案1】:

    不,您需要使用程序化方法。但是,很容易编写一个遍历所有标签的小循环,并为每个标签获取已在界面生成器中设置的动态类型“角色”,并根据该“角色”和所需的自定义字体替换 UIFontMetrics 值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-16
      • 1970-01-01
      • 2017-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-24
      相关资源
      最近更新 更多