Created
November 30, 2011 22:21
-
-
Save nicwise/1411364 to your computer and use it in GitHub Desktop.
BackgroundStringElement
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
// copied from StyledStringElement, I think. | |
// mostly just gets the cell, puts a background on it (which also gets rid of the default | |
// rounded corners etc) and sets the colours on the _existing_ cell.TextLabel and cell.DetailTextLabel | |
public class BackgroundStringElement : StyledStringElement, IElementSizing | |
{ | |
//if you make a new element, you NEED to put in a unique identifier, and use it in the DequeueReusableCell. | |
static NSString skey = new NSString("BackgroundStringElement"); | |
public BackgroundStringElement(string caption) : base(caption) {} | |
public BackgroundStringElement(string caption, string @value) : base(caption, @value) | |
{ | |
} | |
readonly float cellHeight = 25f; | |
public float GetHeight (UITableView tableView, NSIndexPath indexPath) | |
{ | |
return cellHeight; | |
} | |
public UIFont DetailFont; | |
public UIColor DetailTextColor; | |
public override UITableViewCell GetCell (UITableView tv) | |
{ | |
var cell = tv.DequeueReusableCell (skey); | |
if (cell == null){ | |
cell = new UITableViewCell (Value == null ? UITableViewCellStyle.Default : UITableViewCellStyle.Value1, skey); | |
cell.SelectionStyle = UITableViewCellSelectionStyle.None; | |
} | |
cell.BackgroundView = new UIImageView(Resources.InvoiceBackground); | |
/*cell.BackgroundView = new UIView(cell.Frame) { | |
BackgroundColor = UIColor.White | |
}; | |
*/ | |
cell.Accessory = Accessory; | |
var tl = cell.TextLabel; | |
tl.Text = Caption; | |
tl.TextAlignment = Alignment; | |
tl.TextColor = TextColor == null ? UIColor.Black : TextColor; | |
tl.BackgroundColor = BackgroundColor == null ? UIColor.Clear : BackgroundColor; | |
tl.Font = Font == null ? UIFont.SystemFontOfSize (14) : Font; | |
tl.LineBreakMode = LineBreakMode; | |
tl.Lines = 0; | |
// The check is needed because the cell might have been recycled. | |
if (cell.DetailTextLabel != null) | |
{ | |
cell.DetailTextLabel.Text = Value == null ? "" : Value; | |
cell.DetailTextLabel.Font = DetailFont == null ? UIFont.SystemFontOfSize(14) : DetailFont; | |
cell.DetailTextLabel.TextColor = DetailTextColor == null ? UIColor.Black : DetailTextColor; | |
} | |
return cell; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment