0

UILabelの行数を取得して、別のUILabelをテキストの最後の行の下部に移動できるようにする必要があります。私はやった:

int lines = [cellDetailTextLabel.text sizeWithFont:cellDetailTextLabel.font constrainedToSize:cellDetailTextLabel.frame.size lineBreakMode:UILineBreakModeWordWrap].height /16;

ただし、UILabelが3行の場合もあるので、完全ではありませんが、上記のコードは2行しか返しませんが、UILabelの3行すべてには当てはまりません。

4

1 に答える 1

1

UILabelのテキストレイアウトをブラックボックスとして扱うことをお勧めします(テキストが長くなりすぎたときにフォントサイズを自動調整するなどの楽しいことを行います)。

代わりに、UIViewサイジングメソッドの使用を検討してください。

// Ask the label to shrink (or grow) until it fits its text:
[cellDetailTextLabel sizeToFit];
// Get the frame.
CGRect r = cellDetailTextLabel.frame;
// Move its origin to below cellDetailTextLabel
r.origin.y = CGRectGetMaxY(r);
// Set its size to the size of the second label
r.size = cellLabel2.frame.size;
// Finally, move the second label
cellLabel2.frame = r;

iPhone 4でのテキストサイズの奇妙な動作に気づきました(ラベルが高すぎるなどの余分な行になることがあります)。これが4.1で修正されているかどうかはわかりません。

于 2010-09-26T17:57:25.273 に答える