I'm bumping this because I have the very same problem. Here's my code (it goes inside a foreach that cycles through some children labels):
labelName = child.GetComponent<UILabel>();
if (labelName != null) {
labelName.text = item.GetName(); // returns a string with the name of the current item
labelName.ProcessText();
// labelName.ResetAndUpdateAnchors();
Debug.Log(labelName.processedText + ": " + labelName.height);
}
So the Log shows the label text and a height of 32 (font size is 16). In the log, the processed text is displayed in 2 lines, but in the game view (and also the editor) the text is displayed in 3 lines and shows a size of 48 (which is logical, since it's 3 lines of 16 size font).
I tried the simple example of a new empty scene and it works correctly, so any idea of what may have I done wrong? I set the bottom anchor of the label a few lines later, can it be the reason?
// If the label takes more than one line, reposition it related to the type label ("name label" is above "type label")
if (labelName.height > 16) {
// the widget is the one that contains the two labels
labelName.bottomAnchor.Set(widget.transform, (16.0f + labelType.height) / widget.height, 0.0f);
labelName.ResetAndUpdateAnchors();
labelType.topAnchor.Set(widget.transform, (11.0f + labelType.height) / widget.height, 0.0f);
labelType.ResetAndUpdateAnchors();
}
// The values 16 and 11 contain the upper+middle+bottom padding of each label inside the widget
[edit] By the moment I change the anchors, the label.height is already wrong (it shows wrong the very next line of the labelName.ProcessText()) sot the anchoring is not the problem.
[edit 2] Debugging it shows that after calling ProcessText() the value of mProcessedtext includes two lines but the value of mText doesn't (it's all one line). But still, in game mode and editor mode it displays the label as a 3 line label. The values of height are correct, since editor panel shows a height of 48 for the 3 line label but Log shows a height of 32 for a 2 line label. Weird...
[edit 3] Attached 2 screenshots. One showing the label.height as 32 in the log (don't mind the error, I coded it as error but it should be a warning, lol) and the other showing the 3 line label and a size of 48. Both screens happening at the same time.