查找HTML字符串中字符串的显示高度

问题描述:

我有一些HTML,包括文本和图像。查找HTML字符串中字符串的显示高度

我在表格视图单元格内显示UIWebView,所以我需要能够计算单元格的高度。

有没有什么办法可以先计算出渲染高度而不先用UIWebView

+0

从哪里到哪里? – 2013-04-08 10:53:38

NSString *htmlString = @"<p>There are different kinds books</p><p>boos are as follows</p><ul><li>Based on Maths</li><li>Based on science</li><li>Based on Geography</li</ul>"; 
NSScanner *scanner = [NSScanner scannerWithString:htmlString]; 
[scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@">"]]; 
NSMutableString *textFromHTMLString = [[NSMutableString alloc] init]; 
NSMutableString *holder = [[NSMutableString alloc] init]; 
while(![scanner isAtEnd]){ 
    [scanner scanUpToString:@">" intoString:nil]; 
    [scanner scanUpToString:@"<" intoString:&holder]; 

    [textFromHTMLString appendString:holder]; 
} 

NSLog(@"%@", textFromHTMLString);