Is it possible to make UIWebView load a html string but act like a UILabel
-
09-07-2021 - |
Question
TTStyledTextLabel
is exactly what I want, but I don't want to add all Three20 project just for this only one function.
Any suggestions?
La solution
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.
Autres conseils
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]];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow