0

I would like to be able to style the text in a UILabel using CSS. I know that you can use a UIWebView to load HTML to be formatted for display using

[webview loadHTMLString:myText baseURL:nil];

but I would like to simply style just a UILabel without relying on UIWebView. How can I do this?

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
  • Possible duplicate of [How to add CSS of an html to NSAttributedString?](http://stackoverflow.com/questions/22090597/how-to-add-css-of-an-html-to-nsattributedstring) – djdrzzy Sep 14 '16 at 22:10

2 Answers2

0

Look at the open source project called FontLabel at http://wiki.github.com/zynga/FontLabel.

Although it won't let you apply a CSS file to a UILabel, it does provide a subclass of UILabel that can use custom fonts and styling.

Of course you can also use the standard properties of UILabel like color, textAlignment, etc.

Brad The App Guy
  • 16,255
  • 2
  • 41
  • 60
0

Since css file structure is very easy you could create a simple css parser that searches a certain id or class. Then get the font size, name, style and other attributes and instead of using UILabel you maybe want use CATextLayer because text is much more customizable (colors, font, size, style, and even more than one fonts in a single line)

But I wonder why do you need a UILabel and not UIWebView?

Hope it helps

nacho4d
  • 43,720
  • 45
  • 157
  • 240