Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andywhitt/7512433 to your computer and use it in GitHub Desktop.
Save andywhitt/7512433 to your computer and use it in GitHub Desktop.
/*
Xamarin.iOS MonoTouch.Dialog JVFloatSharp Element for gshackles https://github.com/gshackles/JVFloatSharp/
This creates an EntryElement with placeholders that change into floating labels when the field is populated with text.
Andy Whittlestone
*/
public class JVEntryElement : EntryElement
{
public UIColor FloatingLabelTextColor { get; set; }
public UIColor FloatingLabelActiveTextColor { get; set; }
private string _placeHolder;
private bool _isPassword;
private JVFloatLabeledTextField _entry;
private UITextAlignment _textAlignment;
private UIFont _floatingLabelFont = UIFont.BoldSystemFontOfSize(12);
public UIFont FloatingLabelFont {
get { return _floatingLabelFont; }
set { _floatingLabelFont = value; }
}
public new UITextAlignment TextAlignment {
get {
return _textAlignment;
}
set{
_textAlignment = value;
if (_entry != null)
_entry.TextAlignment = _textAlignment;
}
}
public JVEntryElement (string caption, string placeholder, string value) : base (caption, placeholder, value)
{
Value = value;
_placeHolder = placeholder;
}
public JVEntryElement (string caption, string placeholder, string value, bool isPassword) : base (caption, placeholder, value, isPassword)
{
Value = value;
_isPassword = isPassword;
_placeHolder = placeholder;
}
protected override UITextField CreateTextField (RectangleF frame)
{
return _entry = new JVFloatLabeledTextField (frame) {
AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleLeftMargin,
Placeholder = _placeHolder ?? "",
SecureTextEntry = _isPassword,
Text = Value ?? "",
Tag = 1,
TextAlignment = _textAlignment,
ClearButtonMode = ClearButtonMode,
FloatingLabelTextColor = FloatingLabelTextColor,
FloatingLabelActiveTextColor = FloatingLabelActiveTextColor,
FloatingLabelFont = FloatingLabelFont,
};
}
public override UITableViewCell GetCell (UITableView tv)
{
var cell = base.GetCell (tv);
// lets make it fit better to the eye
_entry.Frame = new RectangleF (_entry.Frame.Location.X, 0, _entry.Frame.Width, cell.Frame.Height-5);
return cell;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment