0

I am having one query. I googled it alot but not able to find out its solution.

I am using one api in which I am getting content as HTML string.

Now I want to set that data to UITextView. Now to calculate the height of the UITextView firstly I was using

CGSize constraint = CGSizeMake(width-MARGIN - (6 * 2), 20000.0f);
    // Get the size of the text given the CGSize we just made as a constraint
    CGSize size = [lbltitle.text sizeWithFont:[UIFont fontWithName:custom_font_name size:lbltitle.font.pointSize] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];
    int lines = size.height / lbltitle.font.pointSize + 1;

    [lbltitle setFrame: CGRectMake(lbltitle.frame.origin.x,lbltitle.frame.origin.y,width-MARGIN, lbltitle.font.pointSize * lines)];

but now when I am passing the html content it's generating the height more then the needed. So what is the solution to calculate the height of the UITextview with HTML text. I am using below code to assign HTML text to UITextView.

[txtdescription setValue:data.desc forKey:@"contentToHTMLString"];

Thanks in advance.

BSKANIA
  • 1,317
  • 15
  • 27

2 Answers2

0

You may use UIWebView intead of UITextView

Here

NSData* htmlData = [ content dataUsingEncoding:NSUTF8StringEncoding];
                [webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]];
Macrosoft-Dev
  • 2,195
  • 1
  • 12
  • 15
  • but if I use UIWebView then how can I get the size of UIWebview? and its a iterative list in UITableView so if I will use UIWebView then it will take more load and more memory – BSKANIA Apr 14 '14 at 10:50
  • you draw your web view expanding all the screen with background color is clear. Now html string will have with it and it will draw for . you dont need to calculate size. – Macrosoft-Dev Apr 14 '14 at 10:56
  • but its in UITableView with customcell then how to size the table row height? – BSKANIA Apr 14 '14 at 10:58
  • why not you try attributed string . http://initwithfunk.com/blog/2013/09/29/easy-markdown-rendering-with-nsattributedstring-on-ios-7/ – Macrosoft-Dev Apr 14 '14 at 11:02
0

Hello I found solution of my own question

https://github.com/mwaterfall/MWFeedParser

I need to convert first HTML text to plain text then I can calculate the size.

BSKANIA
  • 1,317
  • 15
  • 27