英文:
UILabel font size fit label width
问题
label.font = UIFont(name: "NanumBarunGothic-YetHangul", size: 10)
label.numberOfLines = 0
label.minimumScaleFactor = 0.5
label.adjustsFontSizeToFitWidth = true
为什么返回大小为10?
我的预测是文本适合UILabel的宽度,并且具有最小大小为0.5的比例。
英文:
type swift
label.font = UIFont(name: "NanumBarunGothic-YetHangul", size: 10)
label.numberOfLines = 0
label.minimumScaleFactor = 0.5
label.adjustsFontSizeToFitWidth = true
Why is the size returned as 10?
My prediction is that the text fits within the width of the UILabel and has a minimum size of 0.5 scale.
答案1
得分: 0
adjustFontSize
会在标签没有足够空间显示时生效(在adjustsFontSizeToFitWidth = false
的情况下)。
标签将显示三个点,例如:some text...
。如果您的标签具有numberOfLine = 0
并且高度没有限制,则字体无需调整,因为内容仍然有足够的空间显示。
英文:
adjustFontSize will be active when the label doesn't have any space to display (in the case adjustsFontSizeToFitWidth = false
).
The label will display three dots, ex: some text...
. If your label has numberOfLine = 0
and does not have a limit on height, the font does not need to fit because the content still has enough space to display.
答案2
得分: 0
10号字体 作为起始点,并可以根据需要缩小,以确保所有文本适应标签宽度,同时保持最小字体缩放因子为0.5。
假设标签文本非常短,如"NanumBarun"。如果文本小到足以适应标签对象的宽度而无需缩小字体大小,则将使用代码中指定的10号字体大小。在这种情况下,minimumScaleFactor 和 adjustsFontSizeToFitWidth 属性将不会产生任何影响,文本将以10号字体大小呈现,标签宽度的剩余空间将为空白。
英文:
The font size of 10 is used as a starting point, and it can be scaled down as needed to ensure that all the text fits within the label width, while maintaining a minimum font scale factor of 0.5.
Suppose the label text is very short, like "NanumBarun". If the text is small enough to fit within the width of the label object without scaling down the font size, then the font size of 10 will be used as specified in the code. In this case, the minimumScaleFactor and adjustsFontSizeToFitWidth properties will not have any effect, and the text will be rendered with the font size of 10 and the remaining space of the label width will be blank.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论