Thanks, Jason and Craig! Those were both helpful. Craig, what you're doing
is way more efficient than how I was going about things.

Of course, it turns out [1] that I'm an idiot and my problem was simpler
than that. My original inline style code was correct...but I forgot to use
string literals for the quotation marks. :-/ 


--Chris

[1] This is really falls more under the heading of "Further Confirmation"
than "New Information".


--Chris


Craig Dunn-2 wrote
> 
> in the Monospace11 app - https://github.com/conceptdev/Monospace11 - some
> of the screens use webviews for formatting (found it faster to format
> nicely, and work cross-platform with Android).
> 
> anyway, check out the
> SpeakerBioViewController<https://github.com/conceptdev/Monospace11/blob/master/iOS/TabSpeakers/SpeakerBioViewController.cs>,
> SessionViewController<https://github.com/conceptdev/Monospace11/blob/master/iOS/TabSessions/SessionViewController.cs>and
> WebViewControllerBase<https://github.com/conceptdev/Monospace11/blob/master/iOS/WebViewControllerBase.cs>
> 
> 
> in the *WebViewControllerBase* class i have a snippet of stylesheet that
> gets re-used on each screen
> 
> public string StyleHtmlSnippet
> {
> get
> {   // http://jonraasch.com/blog/css-rounded-corners-in-all-browsers
> return "";
> }
> }
> 
> and then the code calls 'FormatText()' (which is overridden in the
> subclasses) and display the html in a webview. notice it sets up the base
> directory so that images from inside the app bundle can be displayed (eg.
> background image referenced in the CSS). i've summarised the ViewDidLoad()
> method here:
> 
> basedir = Environment.GetFolderPath
> (System.Environment.SpecialFolder.Personal);
> basedir = System.IO.Path.Combine (basedir, "..", "Monospace11.app"); //
> USE
> YOUR APP BUNDLE NAME
> webView.LoadHtmlString(FormatText(), new NSUrl(basedir, true));
> 
> THEN in the *subclasses*, override FormatText() to return a string of
> HTML,
> incorporating the StyleHtmlSnippet and using styled elements like H2, and
> class = body or sessionspeak...
> 
> protected override string FormatText ()
> {
> StringBuilder sb = new StringBuilder ();
> sb.Append (StyleHtmlSnippet);
> sb.Append ("
" + _speaker.Name + "
" + Environment.NewLine);
> if (!string.IsNullOrEmpty (_speaker.Bio)) {
> sb.Append ("" + _speaker.Bio + "<br/>");
> }
> sb.Append ("<br />");
> foreach (var session in _speaker.Sessions) {
> sb.Append ("<div class='sessionspeaker'> http://MIX10.app/"; +
session.Code + " " + session.Title + " </div><br
> />");
> }
> return sb.ToString ();
> }
> 
> IF you need to catch links inside the HTML and do custom stuff, for more
> info on making the http://MIX10.app urls work, see the
> WebViewDelegate.ShouldStartLoad() methods in each page...
> 
> HTH
> cd
> 
> 




--
View this message in context: 
http://monotouch.2284126.n4.nabble.com/Need-Simple-UIWebView-Example-to-Format-Text-tp4656902p4656912.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to