Search code examples
iosxcodeuilabel

How to Get the Height of a RTLabel


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!


Solution

  • 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);