Created
November 30, 2013 11:02
-
-
Save wayne-o/7717708 to your computer and use it in GitHub Desktop.
Simple webContentElement for iOS dialog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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