我已经走过了什么感觉就像这个方法在SO上的每一篇文章。 很多海报的答案都是把一个非常大的值作为高度限制。我如何正确使用NSString sizeWithFont constratinedToSize与NIAttributedLabel
但是,对我来说这是行不通的。这是我的代码:
//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
一部分。
我没有苹果的文档中读取的方法有时会截断字符串,但我认为多数民众赞成在大高度约束是为
编辑: 我发现它是一个问题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."
描述它如何不工作。截图会很有帮助。你是否一步一步查看标签的最终高度是否确实是'sizeWithFont'中确定的高度?也许NIAttributedLabel实现中有一些怪癖。 – 2012-07-13 08:15:00
我甚至有UILabel类似的问题... – Bharathi 2012-07-13 09:53:44