1

Getting HTML text from back-end, now i am manually removing and formatting the tags and adding bullet points for <li> tags.

if any other <p> tag or <br> tag is coming means then i am removing it. Checked RTLabel, Unable to use this in Interface builder.

Now tried TTTAttributedLabel, i am able to use this in IB but it is not recognizing the HTML tags.

is there any other lightweight library available?

R. Mohan
  • 2,182
  • 17
  • 30
  • You can try using a Webview instead of UILabel...Then you dont have to remove tags manually...Just a suggestion. – Neeraj Sonaro Nov 06 '17 at 11:02
  • actually its a dynamic UITableView, if i use UIWebView then memory issues will come i guess, thats why i am using UILabel. – R. Mohan Nov 06 '17 at 11:08
  • No No...Memory issues will not come....you can go with webview. – Neeraj Sonaro Nov 06 '17 at 11:10
  • `WKWebView` is definitely the solution here. Don't do HTML parsing yourself – Michael Hulet Nov 06 '17 at 11:16
  • 1
    Did you see this notes https://github.com/codepath/objc_ios_guides/wiki/Generating-NSAttributedString-from-HTML ? You can use NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType to convert HTML to NSAttributedString, but it could lead to short app freez for large html page. As I know it's can't be called from the background thread. – Andrew Bogaevskyi Nov 06 '17 at 11:17
  • @AndrewBogaevskyi i tried your suggestion, its working, but the performance is very slow, tableview is strucking. – R. Mohan Nov 06 '17 at 12:26
  • i don't know how to set dynamic height for webview, i tried it now, it seems more complex https://stackoverflow.com/questions/6632596/find-uiwebview-height-dynamically-when-inside-uitableviewcell @NeerajSonaro and atMichael Hulet – R. Mohan Nov 06 '17 at 12:33
  • In that notes, I see the link to DTCoreText. I don't use it but looks good. And this is a discussion about it https://stackoverflow.com/a/4652521/2739795 – Andrew Bogaevskyi Nov 06 '17 at 12:38
  • 1
    https://stackoverflow.com/questions/17204967/how-to-change-the-height-of-webview-dynamically Check this link – Neeraj Sonaro Nov 06 '17 at 13:12
  • @NeerajSonaro thank you for the link you shared, I tried it, the performance is fine, but first time loading the cell webview content is going beyond the row height, while reloading it is fitting fine. – R. Mohan Nov 07 '17 at 05:03

1 Answers1

0

You can use RTLabel to display HTML text instead of UILabel. Please check below link for more details :-

https://github.com/honcheng/RTLabel

Avinay Kumar
  • 163
  • 2
  • 9
  • it is a dynamic uitableview, i cannot set the uilabel text programmatically. thats why i am unable to use this RTLabel library. – R. Mohan Nov 06 '17 at 12:25
  • Ignore above comment. You can calculate height of RTLabel object and assigned height of the cell. For eg :- `RTLabel *lbl = [[RTLabel alloc]initWithFrame:frame]; [lbl setText:@"
    alloc "]; [lbl sizeToFit];` `float fltLBLHeight = lbl.frame.size.height;` Now we can get height of label and use it for dynamic height and assigned it in TableView delegate method "heightForRowAtIndexPath". I hope this could help you !!!
    – Avinay Kumar Nov 06 '17 at 12:48
  • i am not having only this label in my uitableviewcell, the dynamic label will come in between some objects, so i cannot do this by programmatically, previously i tried like this, it performed very slow, that's why using autolayout in IB. – R. Mohan Nov 06 '17 at 12:59