As part of my applications i need to display html contents in uiwebview and the data conatins <ul>
and <li>
tags i am using the attributed string for calculating the height of the webview but whenever data comes with this listed contents it will calculate incorrect height i am stuck with this issue for lat 2 days, when the list contain short text data then it will returns less heights and my contents will misssed when it comes to ipad the issue became worst because of the large width of the 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)];
I got the trick,
just replaced the
<li>
with<br>
before setting it to attributed string