iLe*_*ing 4 .net c# xamarin.ios ios monotouch.dialog
我找不到如何限制字符数 EntryElement
我也喜欢继承和事件:-)试试这个:
class MyEntryElement : EntryElement {
public MyEntryElement (string c, string p, string v) : base (c, p, v)
{
MaxLength = -1;
}
public int MaxLength { get; set; }
static NSString cellKey = new NSString ("MyEntryElement");
protected override NSString CellKey {
get { return cellKey; }
}
protected override UITextField CreateTextField (RectangleF frame)
{
UITextField tf = base.CreateTextField (frame);
tf.ShouldChangeCharacters += delegate (UITextField textField, NSRange range, string replacementString) {
if (MaxLength == -1)
return true;
return textField.Text.Length + replacementString.Length - range.Length <= MaxLength;
};
return tf;
}
}
Run Code Online (Sandbox Code Playgroud)
还可以在这里阅读Miguel的警告(编辑到我的帖子):MonoTouch.Dialog:设置EntryElement的条目对齐