如何从首选字体创建一个轻字体?

时间:2018-04-29 12:57:55

标签: ios xamarin

我试图获得一个"轻盈" UIFontTextStyle字体样式的权重字体 无论代码是什么(在stackoverflow上或在doc中),我总是得到一个正常的"重量字体。

例如:

<div class="container">
  <div class="row" style="background-color: red;">
    <div class="col-12 mh-100 mt-auto" style="overflow-y: auto;">
      <div class="row" style="height: 80px; background-color: blue; border: 4px solid black;"></div>
      <div class="row" style="height: 80px; background-color: blue; border: 4px solid black;"></div>
      <div class="row" style="height: 80px; background-color: blue; border: 4px solid black;"></div>
      <div class="row" style="height: 80px; background-color: blue; border: 4px solid black;"></div>
      <div class="row" style="height: 80px; background-color: blue; border: 4px solid black;"></div>
      <div class="row" style="height: 80px; background-color: blue; border: 4px solid black;"></div>
    </div>
  </div>
</div>

返回正常的重量字体。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。它可能对某人有帮助。

        var style = UIFontTextStyle.Caption2;
        var descriptor = UIFontDescriptor.GetPreferredDescriptorForTextStyle(style);
        var font = UIFont.FromDescriptor(new UIFontDescriptor(new UIFontAttributes
        {
            Family = descriptor.Family,
            Traits = new UIFontTraits
            {
                Weight = (float)GetFontWeight(UIFontWeight.Light)
            }
        }), descriptor.PointSize);