Ios TTTAttributedLabel sizetofit和sizeWithFont不同

Ios TTTAttributedLabel sizetofit和sizeWithFont不同,ios,uilabel,sizetofit,sizewithfont,tttattributedlabel,Ios,Uilabel,Sizetofit,Sizewithfont,Tttattributedlabel,我使用TTtatAttributedLabel,我通常在tableview单元格中使用sizetofit。之后,我在计算单元格高度时使用sizeWithFont。我像这样设置TTtatAttributedLabel [self.attributedLabel setText:@"Test\n\n\n\n"]; CGSize contentSize = [self.attributedLabel.text sizeWithFont:self.attributedLabel.font

我使用TTtatAttributedLabel,我通常在tableview单元格中使用sizetofit。之后,我在计算单元格高度时使用sizeWithFont。我像这样设置TTtatAttributedLabel

[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设备上测试


您应该使用TTtatAttributedLabel的内置方法来计算大小


,这将为您返回一个正确的CGSize。

您应该使用TTTAttributedLabel的内置方法计算大小

,这将为您返回一个合适的CG大小