【发布时间】:2015-06-14 12:21:14
【问题描述】:
作为我的应用程序的一部分,我需要在 uiwebview 和数据 conatins <ul> 和 <li> 标记中显示 html 内容,我使用属性字符串来计算 webview 的高度,但是每当数据带有此列出的内容时,它将计算不正确的高度我被这个问题困住了 2 天,当列表包含短文本数据时,它将返回更少的高度,并且我的内容将在 ipad 时丢失,由于 webview 的宽度过大,问题变得最严重.
NSMutableAttributedString *htmlString1 =
[[NSMutableAttributedString alloc] initWithData:[[self.doctorDetail objectForKey:@"Description"] dataUsingEncoding:NSUTF8StringEncoding]
options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute:[NSNumber numberWithInt:NSUTF8StringEncoding]}
documentAttributes:NULL error:nil];
[htmlString1 addAttributes:attrsDictionary range:NSMakeRange(0, htmlString1.length)];
CGSize discriptionsize = CGSizeMake(self.discriptionLabel.frame.size.width, FLT_MAX);
CGRect textRect = [htmlString1 boundingRectWithSize:discriptionsize options:NSStringDrawingUsesLineFragmentOrigin context:nil];
CGSize expectedLabelSize = CGSizeMake(textRect.size.width, textRect.size.height);
[self.discriptionLabel setFrame:CGRectMake(self.discriptionLabel.frame.origin.x, self.doctorImage.frame.origin.y+self.doctorImage.frame.size.height+5, self.discriptionLabel.frame.size.width, expectedLabelSize.height+10)];
【问题讨论】:
标签: ios uiwebview nsattributedstring