Last active
August 29, 2015 14:06
-
-
Save chrisdiana/39b8a7da06c1da5ce14f to your computer and use it in GitHub Desktop.
Text Field Validation for UITextField in Xamarin
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
// sample text field | |
var titleField = new UITextField (new RectangleF (0, 160, UIScreen.MainScreen.Bounds.Width, 50)){ | |
BackgroundColor = UIColor.White, | |
TextColor = ViewHelpers.DarkGray, | |
Placeholder = "Title:" | |
}; | |
// validation | |
titleField.EditingDidEnd += (object sender, EventArgs e) => { | |
if ( ((UITextField)sender).Text.Length <= 0 ) { | |
InvokeOnMainThread ( () => { | |
titleField.Layer.BorderColor = ViewHelpers.DarkBlue.CGColor; | |
titleField.Layer.BorderWidth = 2; | |
titleField.Text = "Please fill in the Title:"; | |
} ); | |
}else if ( ((UITextField)sender).Text.Length > 0 ){ | |
titleField.Layer.BorderColor = ViewHelpers.DarkBlue.CGColor; | |
titleField.Layer.BorderWidth = 0; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment