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.
2
Answers
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 hasnumberOfLine = 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.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.