I'm using Monotouch.Dialog and need to reposition some EntryElements - they seem to drift right when inside a Section.
I am setting the frame to frame.X = frame.X - 5;
to account for this. However if the cell goes off screen and then is scrolled back on the frame seems to be reset and the UI looks out of line.
What can I do to ensure the frame is never reset or at least set back to what it should be?
Here is the code - this is using the MvvmCross port of Monotouch.Dialog so GetCell is now GetCellImpl - it works in pretty much the same way - thing is dequeuereusablecell is called in it's base class (EntryElement) and I am modifying the cell after that point anyway... so should work no?:
public class MyEntryElement : EntryElement, IElementSizing
{
public bool Disabled {
get;
set;
}
public MyClaimEntryElement()
: base()
{
}
public MyEntryElement(string caption)
: base(caption)
{
}
public MyEntryElement(string caption, string placeholder)
: base(caption, placeholder)
{
}
public MyEntryElement(string caption, string placeholder, string value)
: base(caption, placeholder, value)
{
}
public MyEntryElement(string caption, string placeholder, string value, bool isPassword)
: base(caption, placeholder, value, isPassword)
{
}
protected override UITableViewCell GetCellImpl(UITableView tv)
{
var cell = base.GetCellImpl(tv);
cell.BackgroundColor = UIColor.Clear;
UITextField uiTextField;
if (cell.ContentView.Subviews.Length == 1)
{
uiTextField = ((UITextField)cell.ContentView.Subviews[0]);
}
else
{
uiTextField = ((UITextField)cell.ContentView.Subviews[1]);
}
if (cell.ContentView.Subviews.Length == 2) {
var labelField = ((UILabel)cell.ContentView.Subviews [0]);
labelField.TextColor = UIColor.White;
}
uiTextField.Enabled = Disabled;
uiTextField.TextColor = UIColor.Black;
uiTextField.Background = UiHelper.Text_Bubble;
uiTextField.Enabled = !Disabled;
var frame = uiTextField.Frame;
frame.X = frame.X - 5;
frame.Height = frame.Height + 10;
uiTextField.Frame = frame;
return cell;
}
private const float CellHeight = 40; //standard height. You can make it bigger or smaller, tho smaller means fingers miss easier.
public float GetHeight(UITableView tableView, NSIndexPath indexPath)
{
return CellHeight;
}
}