1

I am using TTTAttributedLabel and I usually use sizetofit in my tableview cell. After that, I use sizeWithFont in my cell height calculation. I set TTTAttributedLabel like this.

[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];

I notice that height is different. I got my output like this. So I guess it is wrong. May I know how to fix? I am testing on iOS 8 device.

enter image description here

Khant Thu Linn
  • 5,905
  • 7
  • 52
  • 120

1 Answers1

5

You should calculate sizing instead with TTTAttributedLabel's built-in method

+[TTTAttributedLabel sizeThatFitsAttributedString: withConstraints:limitedToNumberOfLines:, which will return a proper CGSize for you.

Jonathan Hersh
  • 1,073
  • 1
  • 8
  • 15