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

时间:2013-04-08 10:49:02

标签: ios cocoa-touch uiwebview

我有一些HTML,包括文字和图片。

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

有没有办法在不先使用UIWebView的情况下计算渲染高度?

1 个答案:

答案 0 :(得分:0)

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