我正在尝试将UIWebView
子类化以显示格式化的降价。不幸的是,我遇到了两个似乎无法解决的问题。
MvvmCross
动态绑定的内容动态设置视图的高度。 如何解决这两个问题?
我附上了当前进度的截图,以及我用来生成它的代码。
using System;
using System.Drawing;
using System.IO;
using System.Text;
using FutureState.BreathingRoom.Touch.Ui.Resources;
using MarkdownDeep;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace FutureState.BreathingRoom.Touch.Ui.Controls
{
public class FsmUIMarkdownView : UIWebView
{
private readonly Markdown _markdownDeep;
private string _markdown;
public FsmUIMarkdownView()
{
_markdownDeep = new Markdown();
SetLayoutInfo();
}
public FsmUIMarkdownView(RectangleF frame)
: base(frame)
{
_markdownDeep = new Markdown();
SetLayoutInfo();
}
public string Markdown
{
get { return _markdown; }
set
{
if (string.IsNullOrEmpty(value) || _markdown == value) return;
_markdown = _markdownDeep.Transform(value);
var html = new StringBuilder();
html.Append("<html>");
html.Append("<head>");
html.Append("<style type = \"text/css\">");
html.Append("body {font-family:helvetica;font-size:15; margin:0; padding:0;}");
html.Append("p {margin:0; padding:5;}");
html.Append("</style>");
html.Append("</head>");
html.Append("<body>");
html.Append(_markdown);
html.Append("</body>");
html.Append("</html>");
var contentDirectoryPath = Path.Combine(NSBundle.MainBundle.BundlePath, "/");
LoadHtmlString(html.ToString(), new NSUrl(contentDirectoryPath, true));
UpdateSize();
HandleHtmlContentChanged();
}
}
private void UpdateSize()
{
}
private void SetLayoutInfo()
{
Layer.CornerRadius = 3;
Layer.BorderColor = CustomUIColor.breathingroom_borders.CGColor;
Layer.BackgroundColor = UIColor.White.CGColor;
ClipsToBounds = true;
}
public event EventHandler HtmlContentChanged;
private void HandleHtmlContentChanged()
{
var handler = HtmlContentChanged;
if (handler != null)
handler(this, EventArgs.Empty);
}
}
}