Last active
August 29, 2015 14:06
-
-
Save chrisdiana/5045a2322fe832fe32ca to your computer and use it in GitHub Desktop.
Text Box Validation for UITextView 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 box | |
var descriptionField = new UITextView (new RectangleF (0, 230, UIScreen.MainScreen.Bounds.Width, 100)){ | |
BackgroundColor = UIColor.White, | |
Text = " Description:", | |
TextColor = ViewHelpers.DarkGray, | |
Font = UIFont.FromName("Helvetica", 18f) | |
}; | |
// validation | |
descriptionField.ShouldEndEditing = t => { | |
if (string.IsNullOrEmpty (descriptionField.Text)) { | |
descriptionField.Layer.BorderColor = ViewHelpers.DarkBlue.CGColor; | |
descriptionField.Layer.BorderWidth = 2; | |
descriptionField.Text = " Please fill in a Description:"; | |
} else if (descriptionField.Text.Length > 0) { | |
descriptionField.Layer.BorderWidth = 0; | |
} | |
return true; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment