Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to display html text on a label(TTStyleLabel). I am receieving text in form of html. How do I calculate height of html string?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
811 views
Welcome To Ask or Share your Answers For Others

1 Answer

To get height of html text you need to put that html info uiwebview. After loading the html in uiwebview you can get its height in its delegate methods like this -

- (void)viewDidLoad
{
    [super viewDidLoad];
    webview.delegate = self;
    [webview loadHTMLString:@"<div id='foo' style='background: red'>The quick brown fox jumped over the lazy dog.</div>" baseURL:nil];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString *output = [webview stringByEvaluatingJavaScriptFromString:@"document.getElementById("foo").offsetHeight;"];
    NSLog(@"height: %@", output);
}

But if you are not displaying the text on the screen using the webview (as you are using a TTStyleLabel) you can hide the webview and load the html in it. You need to perform some tricks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...