2

Is there any trick so i can give html formatted text to e.g. UILabel or UITextField and iphone will format the text accordingly?

For example if there is a bold tag, the text will be bolded.

DixieFlatline
  • 7,895
  • 24
  • 95
  • 147

7 Answers7

1

You can try with NSAttributedString

label.attributedText =
[[NSAttributedString alloc]
          initWithData: [html dataUsingEncoding:NSUTF8StringEncoding]
               options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType }
    documentAttributes: nil
                 error: &err];
Irshad
  • 445
  • 5
  • 16
1

No, the only class I know in iOS that displays HTML is UIWebView. Of course, you can use a small web view to display some HTML to get text styles. But if you're only want to draw static styled text in a view you can use CoreText. There are many examples out there (including one from Apple called CoreTextPageViewer) of how to draw an NSAttributedString with CoreText.

Hope that helps!

Sebastian
  • 904
  • 1
  • 8
  • 16
1

try with NSAttributedString.

https://nodeload.github.com/AliSoftware/OHAttributedLabel/zipball/master

inthis example ,they show on UILable

aViNaSh
  • 1,318
  • 14
  • 15
0

Only UIWebView supports html but you should also checkout this repo on github -

https://github.com/honcheng/RTLabel

saadnib
  • 11,145
  • 2
  • 33
  • 54
0

i think it is better way display HTML content in UIwebview compare to handle in other component

Droid
  • 1,091
  • 2
  • 9
  • 14
  • 1
    Our customers want to have some control over how certain parts of the app look, so we were considering this option because Android has some good classes for this: http://developer.android.com/reference/android/text/Html.html – DixieFlatline Aug 29 '11 at 14:11
  • We were thinking about letting them put their html on server and fetching it with our android/iphone apps. – DixieFlatline Aug 29 '11 at 14:21
0

Take a look at HTML String content for UILabel and TextView Where he mentions about "Three20 project which includes a class TTStyledTextLabel which allows you to render HtmL-Code and even activates links"

Community
  • 1
  • 1
0x8badf00d
  • 6,391
  • 3
  • 35
  • 68
0

Short answer, no.

To display HTML you need to use a UIWebView. If you want a rich text editor then you need to look at 3rd party Such as three20. Or on iOS > 4 you can use contentEditable in a UIWebView

Jonathan.
  • 53,997
  • 54
  • 186
  • 290
  • I can't find a method called 'contentEditable' in UIWebView... what is it? – Sebastian Aug 30 '11 at 09:27
  • It isn't a method, it is a HTML property. So you would put your HTML inside an element with contentEditable set to true, e.g.: `
    some html to display
    `
    – Jonathan. Aug 30 '11 at 10:11