複数行にわたったテキストを含むUILabelを適切な高さに調節する。

複数行にわたったテキストを表示するためのUILabelのインスタンスであるlabelがあり、そのlabelを適切なサイズ高さに変更したい時がありました。

// すでに以下の2行は他の部分で設定されている。
[label setLineBreakMode:UILineBreakModeWordWrap];
[label setNumberOfLines:0];

CGRect *frame;

frame = [label frame];
frame.size = CGSizeMake(WIDTH, 0);

[label setFrame:frame];
[label setText:@"long long long text..."];
[label sizeToFit];

ポイントはnumberOfLinesを0にすることと、sizeToFitメッセージを呼び出すこと。
numberOfLinesを0にしないと、sizeToFitを呼び出した時点で、指定した幅が無視されてしまう気がする。

毎回frameの幅を決めているのは、テキストが何度も書き換わる場所だから。
テキストが短いものになった場合、sizeToFitメッセージで短い幅が設定されてしまうと以降ずっとその短い幅になったままになってしまうため。

でもAppleのドキュメントには、以下のようにsizeToFitメッセージはnumberOfLinesを考慮するって書いてある。
自分のやり方がおかしいのか?

UILabel Class Reference」より抜粋

When the receiver is resized using the sizeToFit method, resizing takes into account the value stored in this property. For example, if this property is set to 3, the sizeToFit method resizes the receiver so that it is big enough to display three lines of text.

引用元: UILabel Class Reference