How to calculate height of html string?

后端 未结 1 2027
我在风中等你
我在风中等你 2020-12-17 05:34

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?

1条回答
  •  没有蜡笔的小新
    2020-12-17 06:26

    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:@"
    The quick brown fox jumped over the lazy dog.
    " 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.

    0 讨论(0)
提交回复
热议问题