我已经在 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 它可以完美地工作。这是两个源字符串和相应的屏幕截图,第一个展示了我的问题,另一个决定没问题:
"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."