I need to draw a label that has some words in bold, consists of several paragraphs with different paddings and may contain small inline images (e.g. icons and bullets) from resources.
I know I could use NSAttributedString for bold and italic but it doesn’t support paragraph margins or line limiting, and I’d rather use HTML/CSS-like solution because I’m getting the styles from server. It also won’t allow me to insert my custom images in text without resorting to wrapping them in custom fonts.
Finally, I don’t want to use UIWebView for performance reasons.
What MonoTouch libraries or bindings can I use to achieve this?
I was happy to find out Hulu engineers wrote an iOS library that does exactly that. It’s called GSFancyText.
In their own words:
The library is awesome so we went with creating MonoTouch bindings for it.
Example
First define the styles using a CSS-like string:
Then create a
GSFancyTextobject with a markup string:Then you can directly draw this in a customized view:
Or create a GSFancyTextView object to display it
You can find more examples in GSFancyTextView documentation.
My favorite feature are lambda blocks which allow you to specify a delegate to be called to render a
<lambda id=yourhandler width=50 height=50>pseudoelement.This allows you to insert custom images or do advanced inline drawing yourself.