3

Does anyone know how to get the height of a RTLabel?

What I need to do is to adjust the height of the parent view of the RTLabel base on the same RTLabel height.

Thanks!

jmoukel
  • 794
  • 6
  • 18

2 Answers2

7

To get height of RTLabel use "optimumSize" property

RTLabel *someLabel = [[RTLabel alloc] init];
someLabel.frame = CGRectMake(0.f, 0.f, 300.f,100.f);
someLabel.text = @"<p>Some <b>HTML</b></p>";
CGSize optimumSize = [someLabel optimumSize];
someLabel.frame = CGRectMake(0.f, 0.f, 300.f,optimumSize.height);
kolyancz
  • 132
  • 1
  • 8
0

I think it's just

CGFloat height = CGRectGetHeight(rtLabel.bounds)
Mike Szyndel
  • 10,461
  • 10
  • 47
  • 63
ansible
  • 3,569
  • 2
  • 18
  • 29
  • 1
    A bit nicer would be to read it out using `CGRectGetHeight()`, i.e `CGFloat height = CGRectGetHeight(rtLabel.bounds);` Also, Apple has suggested not to name ivars with [leading underscore](http://stackoverflow.com/questions/3521254/prefixing-property-names-with-an-underscore-in-objective-c), just something to keep in mind. – Henri Normak Jan 13 '14 at 19:22
  • Updated, I was just using the project for RTLabel from Github -https://github.com/honcheng/RTLabel, but change it to just rtLabel. – ansible Jan 13 '14 at 19:26