Skip to content

Instantly share code, notes, and snippets.

@wayne-o
Created November 30, 2013 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wayne-o/7717708 to your computer and use it in GitHub Desktop.
Save wayne-o/7717708 to your computer and use it in GitHub Desktop.
Simple webContentElement for iOS dialog
public class WebContentElement : Element, IElementSizing
{
public enum CellFlags
{
Transparent = 1,
DisableSelection = 2
}
private readonly NSString _key;
public CellFlags Flags;
private UITableViewCell _currentCell;
private UIWebView _webView;
private readonly RectangleF _frame;
public WebContentElement(String content, String caption, RectangleF frame)
: base(caption)
{
_frame = frame;
_key = new NSString("rbhtml_row");
InitWebView(content);
}
protected override NSString CellKey
{
get { return _key; }
}
public float GetHeight(UITableView tableView, NSIndexPath indexPath)
{
return _webView.Bounds.Height;
}
private void InitWebView(string content)
{
_webView = new UIWebView(_frame);
_webView.ScrollView.ScrollEnabled = true;
_webView.LoadHtmlString(content, new NSUrl(""));
}
protected override UITableViewCell GetCellImpl(UITableView tv)
{
UITableViewCell cell = tv.DequeueReusableCell(CellKey);
if (cell == null)
{
cell = new UITableViewCell(UITableViewCellStyle.Default, CellKey);
if ((Flags & CellFlags.Transparent) != 0)
{
cell.BackgroundColor = UIColor.Clear;
cell.BackgroundView = new UIView(RectangleF.Empty)
{
BackgroundColor = UIColor.Clear
};
}
cell.SelectionStyle = UITableViewCellSelectionStyle.None;
cell.ContentView.AddSubview(_webView);
}
_currentCell = cell;
return cell;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment