PRGValidationField
is a flexible and customizable implementation of a self validating Text Field.
It is written in Swift 3.0 and Compatible with iOS 9.0+
To start using the component add it to your project manually as per the Installation section.
The UI component can be used via the PRGValidationField
class.
To create an instance of the class, drag a UIView from the Interface builder and set it's class to PRGValidationField.
PRGValidationField
is @IBDesinable
and customizable via @IBInspectable
properties, this way almost everything can be done via the interface builder.
The properties are pretty straightforward and documented in-code but here are the most important things you need to know:
The title of the Field, for example: "Email Address"
@IBInspectable var fieldTitle: String
The fonts used for the Field's Title, The Error Message and The Field itself.
As @IBInspectable
's do not cover fonts, If you are using custom fonts you can type the name of the font (the same way you would type it programmaticaly) followed by a comma (",") and the desired size of the font. Do not forget to add all custom fonts on Info.plist OR use an awesome library called FontBlaster which does that automatically.
If the font you supplied is not found, the fallback font is the system font.
@IBInspectable var textFont: String
@IBInspectable var titleFont: String
@IBInspectable var errorFont: String
The color of the Field's Title and Error Message.
@IBInspectable var titleColor: UIColor
@IBInspectable var errorColor: UIColor
The DEFAULT color of the Field's Background, Border and it's Text.
@IBInspectable var bgColor: UIColor
@IBInspectable var borderColor: UIColor
@IBInspectable var textColor: UIColor
The [VALID] state color of the Field's Background, Border, Text as well as the right view indicator image
@IBInspectable var validBorderColor: UIColor
@IBInspectable var validBgColor: UIColor
@IBInspectable var validTextColor: UIColor
@IBInspectable var validImage: UIImage
The [INVALID] state color of the Field's Background, Border, Text as well as the right view indicator image
@IBInspectable var invalidBorderColor: UIColor
@IBInspectable var invalidBgColor: UIColor
@IBInspectable var invalidTextColor: UIColor
@IBInspectable var invalidImage: UIImage
You can set the validation mode programmaticaly:
enum ValidationMode: Int {
case name = 0,email,password,confirmPassword
}
nameField.validationMode = .name
@IBInspectable
property to set validation mode (See ValidationMode Enum)
0 = Name , Surname
1 = Email
2 = Password
3 = Confirm PassWord
Getter for the text field's text
public var text: String?
Set this in order for "Password" and "Confirm Password" fields to be able to see each other. NOTE: Only set one of two fields. Only password field or confirm password field
weak var otherPasswordField: PRGValidationField
Get the validation status of the Text Field
var isValid: Bool?
There is one optional callback function:
@objc optional func PRGValidationField(_field: PRGValidationField, didValidateWithResult result: Bool, andErrorMessage errorMessage: String?)
Just clone this repo and copy the PRGValidationField folder into your project.
Coming soon.
We welcome all contributions. Please contanct me or submit a pull request, and I will give you an e-Cookie :)
PRGValidationField
is made for Programize LLC by John Spiropoulos and it is available under the MIT license.