我使用的是TTTAttributedLabel,我通常在我的桌面单元格中使用using。在此之后,我使用sizeWithFont计算我的单元格高度。我把TTTAttributedLabel设成这样。
[self.attributedLabel setText:@"Test\n\n\n\n"];
CGSize contentSize = [self.attributedLabel.text sizeWithFont:self.attributedLabel.font
constrainedToSize:CGSizeMake(CGRectGetWidth(self.attributedLabel.frame), 1000)
lineBreakMode:NSLineBreakByWordWrapping];
[self.attributedLabel sizeToFit];我注意到身高是不同的。我的输出是这样的。所以我想这是错误的。我能知道怎么修理吗?我正在iOS 8设备上进行测试。

发布于 2015-05-07 23:01:06
您应该使用TTTAttributedLabel的内建方法来计算大小。
[+[TTTAttributedLabel sizeThatFitsAttributedString: withConstraints:limitedToNumberOfLines:](https://github.com/TTTAttributedLabel/TTTAttributedLabel/blob/1.13.3/TTTAttributedLabel/TTTAttributedLabel.h#L277-L288),它将为您返回一个适当的CGSize。
https://stackoverflow.com/questions/30079813
复制相似问题