SOでのこの方法に関するすべての投稿のように感じるものを確認しました。そして、ポスターの答えの多くは、高さの制約として非常に大きな値を設定することです。
しかし、私にとってこれは機能していません。これは私のコードです:
//Create the contentLabel Label
CGSize size = [contentText sizeWithFont:[UIFont fontWithName:@"Helvetica" size:14] constrainedToSize:CGSizeMake(286, 9999) lineBreakMode:UILineBreakModeWordWrap];
//Create the content label with its position 7 pixels below the title
contentLabel = [[NIAttributedLabel alloc] initWithFrame:
CGRectMake(7, titleContainerView.frame.origin.y + 7, 286, size.height)];
//Set the provided text and the font
contentLabel.font = [UIFont fontWithName:@"Helvetica" size:14];
contentLabel.numberOfLines = 0;
contentLabel.lineBreakMode = UILineBreakModeWordWrap;
contentLabel.text = contentText;
私が使用しNIAttributedLabel
ているのは、間違ったサイズであると私が信じているものを返すメソッドがの一部であるため、これは実際には効果がないはずだと思いましたNSString
。
私はAppleのドキュメントを読んで、メソッドが文字列を切り捨てることがあることを読みましたが、それが大きな高さの制約の目的であると思いました
編集:
私はそれが問題であることを発見しましたNIAttributedLabel
、私が通常のUILabelを使用する場合、それは完全に機能します。これが2つのソース文字列と対応するスクリーンショットです。最初は私の問題を示しており、もう1つは問題ないと判断しています。
"Buying a Mobile\nHello - I'd like a Motorola Defy with a Smartphone 60 Plan.\nBroadband Problem\nMy Broadband’s out. I've tested the router and cables and ruled out my equipment. Is there a problem at your end?"
"Buying a Mobile\nI\'m Mrs Sina Manu-Harris. My account number is 156205169. I\'m going overseas in 6 months time on the 2nd of September and I\'d like to get organized in advance and buy a new mobile phone.\nBroadband Problem\nGood afternoon. It’s Mrs Sina Manu-Harris here. My account number is 156205169. My Broadband isn’t working. I’ve checked my network and phone cables and I've also checked my filters."