`minimumScaleFactor` 不会改变 `UILable` 的size

根据文档,当 minimumScaleFactor 设置为小数,并且 adjustsFontSizeToFitWidthtrue时,系统会调整 fontsize 来尽可能确保可以显示完整的文字。

Normally, the label text is drawn with the font you specify in the font property. If this property is set to true, and the text in the text property exceeds the label’s bounding rectangle, the label reduces the font size until the string fits or the minimum font scale is reached.

但是 label 的整体 size 会不会改变呢?

实验及结果

我做了四组对照,每一组都有两个label,所有的label宽度都是相同的,minimumScaleFactor 设置为 0.5, adjustsFontSizeToFitWidth 为true

  1. 上面的label的文字很短,所以不需要调整font的大小。 下面label的顶部距离下面label底部距离是5.
  2. 上面label文字很长,所以需要调整font的大小。下面label的顶部距离下面label底部距离是5.
  3. 上面label文字很长,所以需要调整font的大小。下面label通过Baseline来约束。
  4. 上面label文字很短,所以不需要调整font的大小。下面label通过Baseline来约束。

结果如下

1. 虽然第二组中,label很长,font很小,但是大小和第一组的相同,没有变化。
2. 第三和第四组比较,虽然用来显示的font不同,但是用来决定distance between the two anchors并没有变化。

Simulator Screen Shot - iPhone 11 Pro Max - 2020-03-09 at 10.31.22

link

-demo

posted on 2020-03-09 11:06  花老🐯  阅读(661)  评论(0编辑  收藏  举报

导航