Domanda

TTStyledTextLabel is exactly what I want, but I don't want to add all Three20 project just for this only one function. Any suggestions?

È stato utile?

Soluzione

If you are OK with limiting the application to iOS 6+, Attributed string support is available on all standard rendering controls, if not, there are many other 3rd party solutions available (including my favorite, OHAttributedLabel). Just don't use a WebView for something this simple, they are really really heavy objects.

Altri suggerimenti

Yes, you may use – stringByEvaluatingJavaScriptFromString:

Say you load this string to webView:

<div id="msg">
    Super inner html with <b>bold</b>
</div>

Then you may get msg's inner html like this:

NSString* value = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('msg').innerHTML"];

And set msg's inner html like this:

[webView stringByEvaluatingJavaScriptFromString:
    [NSString stringWithFormat:@"document.getElementById('msg').innerHTML = '%@'", newValue]];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top