Created
May 17, 2010 18:04
-
-
Save martinbowling/404031 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 AutoGrowDateElement : DateTimeElement, IElementSizing { | |
static NSString bkey = new NSString ("AutoGrowDateElement"); | |
public AutoGrowDateElement (string caption, DateTime date) : base (caption, date) | |
{ | |
fmt.DateStyle = NSDateFormatterStyle.Medium; | |
} | |
public override string FormatDate (DateTime dt) | |
{ | |
return fmt.ToString (dt); | |
} | |
public override UIDatePicker CreatePicker () | |
{ | |
var picker = base.CreatePicker (); | |
picker.Mode = UIDatePickerMode.Date; | |
return picker; | |
} | |
public override UITableViewCell GetCell (UITableView tv) | |
{ | |
Value = FormatDate (DateValue); | |
float tlHeight = GetTextLabelHeight(tv); | |
var cell = tv.DequeueReusableCell (bkey); | |
if (cell == null){ | |
cell = new UITableViewCell (UITableViewCellStyle.Default, bkey); | |
cell.SelectionStyle = UITableViewCellSelectionStyle.None; | |
} else | |
RemoveTag (cell, 1); | |
//cell.TextLabel.Text = Caption; | |
UILabel newLabel = new UILabel(new RectangleF(10,10,175, tlHeight-20)); | |
newLabel.LineBreakMode = UILineBreakMode.WordWrap; | |
newLabel.Font = UIFont.FromName ("Helvetica", 14f); | |
newLabel.Lines = 0; | |
newLabel.Text = Caption; | |
cell.ContentView.AddSubview(newLabel); | |
if (Value != null) | |
{ | |
UILabel valueLabel = new UILabel(new RectangleF(190,10,100,tlHeight-20)); | |
valueLabel.Font = UIFont.BoldSystemFontOfSize(14); | |
valueLabel.LineBreakMode = UILineBreakMode.WordWrap; | |
valueLabel.Lines = 0; | |
valueLabel.Text = Value; | |
cell.ContentView.AddSubview(valueLabel); | |
} | |
return cell; | |
} | |
public float GetTextLabelHeight (UITableView tableView) | |
{ | |
SizeF size = new SizeF (175, float.MaxValue); | |
using (var font = UIFont.FromName ("Helvetica", 14f)) | |
{ | |
if ((tableView.StringSize (Caption, font, size, UILineBreakMode.WordWrap).Height + 20) > 48) | |
{ | |
return tableView.StringSize (Caption, font, size, UILineBreakMode.WordWrap).Height + 20; | |
} | |
else | |
{ | |
return 48; | |
} | |
} | |
} | |
public float GetHeight (UITableView tableView, NSIndexPath indexPath) | |
{ | |
SizeF size = new SizeF (175, float.MaxValue); | |
using (var font = UIFont.FromName ("Helvetica", 14f)) | |
{ | |
if ((tableView.StringSize (Caption, font, size, UILineBreakMode.WordWrap).Height + 20) > 48) | |
{ | |
return tableView.StringSize (Caption, font, size, UILineBreakMode.WordWrap).Height + 20; | |
} | |
else | |
{ | |
return 48; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment