EnterpriseDS Documentation

Class DSText​Field

@IBDesignable public final class DSTextField: UIView, UITextInputTraits  

An Enterprise-styled text entry element. It includes properties for providing a placeholder label, helper text that sits below it that educates the user on what text to enter, and DSInputMask and DSValidationRule rules which will determine user input format and display errors when validations failed.

The renderingType decides the appearance of the text field.

The field defaults to single-line, but if isMultiline is set to true the field will grow vertically as text is entered and space is required. When single-line, a UITextField will be used, a UITextView otherwise.

If you need to set field-specific properties such as returnKeyType or autocapitalizationType, use the properties on DSTextField when available. For anything more advanced, the textView and textField properties can be used for direct access.

Use the DSInputMask framework to control text input based on the type of data being entered. There are many built-in rules to use or you can implement your own.

Use the DSValidationRule framework to add one or more validation checks. There are many built-in rules to use or you can implement your own.

For storyboards, add a UIView to your view and change the class name to DSTextField. Also, note that in the storyboard the checkbox for Accessibility is unchecked, however, it will be enabled by default. Ignore the value of this checkbox. If you want to set this value to false, you must do so in code by setting isAccessibilityElement to false.

Since this component can shrink and grow vertically to accommodate its contents, it's recommended that the DSTextField be embedded in a UITableView that makes it easy for its contents to resize smoothly vertically. The easiest way to do this is to use the DSTextFieldDelegate method textFieldDidLayout which gets called when the size changes. Implement it somewhat as follows:

textFieldDidLayout(_ textField: DSTextField) {

Initialize and set properties as needed.

let bioField = DSTextField(renderingType: .standard)

bioField.labelText = "Bio"
bioField.helperText = "XXX-XXX-XXXX"
bioField.addValidationRule(RequiredValidationRule(message: "Bio is required."))
bioField.clearButtonMode = .whileEditing
DSTextField DSTextField DSTextEntryAreaDelegate DSTextEntryAreaDelegate DSTextField->DSTextEntryAreaDelegate UITextInputTraits UITextInputTraits DSTextField->UITextInputTraits UIView UIView DSTextField->UIView

Conforms To




public init(renderingType: DSTextFieldRenderingType = .cell)  



@IBOutlet public weak var textFieldDelegate: DSTextFieldDelegate?  

The delegate which receives updates on the DSTextField's state.


@IBInspectable public var isMultiline: Bool = false  

When true, the field will grow vertically as more text is entered. This is similar to standard UITextView behavior except the vertical size is the minimum required to display all text.


@IBInspectable public var isEnabled: Bool = true  

Returns true if the component is enabled and allows text editing.


@IBInspectable public var prefixText: String?  

The text to be displayed in the first position of the DSTextField.


@IBInspectable public var labelText: String?  

The text to be displayed in the DSTextField's label.


@IBInspectable public var helperText: String?  

The text to be displayed as helper to the user on what to enter into the field.


@IBInspectable public var isSecureText: Bool = false  

The text is sensitive and you should be protected from viewing. Replaces characters with dots.


@IBInspectable public var showsShowHideButtonWithSecureText: Bool = true  

When isSecureText is true, this property determines if a show/hide button should display. Doesn't have any effect unless isSecureText is true.


@IBInspectable public var text: String?  

The text entered into the DSTextField.


public var validationState: DSValueValidationState  

The current validation state based on validation rules you have.


@IBInspectable public var appliesBackgroundColorToSuperview: Bool = false  

Automatically makes superview background color match when enabled/disabled


public var inputMask: DSInputMask?  

An input mask that formats entered text and/or prevents certain characters from being entered at all


public var rawText: String  

Returns the raw text entered into the DSTextField if a DSInputMask is defined, otherwise returns the text as displayed.


public var unprefixedText: String  

Returns the text as it appears in DSTextField minus prefixing.


public var validationRules  

The array of ValidationRule objects to be used for validating the current state of the DSTextField contents.


public var isValid: Bool  

Returns true if there are no validations or any validations that exist pass.


public var returnKeyType: UIReturnKeyType = .default  

Specifies the type of return button type of the associated keyboard for the field


public var keyboardType: UIKeyboardType = .default  

Specifies the type of keyboard for the field


public var textContentType: UITextContentType! = nil  

Specifies the semantic meaning for the field


public var autocorrectionType: UITextAutocorrectionType = .default  

Specifies if words should be autocorrected as typed


public var spellCheckingType: UITextSpellCheckingType = .default  

Specifies if words should be spell checked as typed


public var autocapitalizationType: UITextAutocapitalizationType = .sentences  

Specifies how capitalization happens as typed


public override var accessibilityLabel: String?  

Specifies the accessibilityLabel for the entire field


public var textView: UITextView!  

The embedded UITextView in case additional customization is needed. (Note that some properties might be overridden by DSTextField, so try to avoid this if at all possible.)


public var textField: UITextField!  

The embedded UITextField in case additional customization is needed. (Note that some properties might be overridden by DSTextField, so try to avoid this if at all possible.)


public var renderingType: DSTextFieldRenderingType = .cell  

The visual style of the field. Can be changed after initialization.


@IBInspectable public var renderingTypeString: String  

The renderingType property representable by a String.

This property is only recommended for use in the Attributes inspector of a storyboard since enums are not @IBInspectable. Possible values are standard and freeform. In code, use the renderingType property instead.


public var clearButtonMode: UITextField.ViewMode = .whileEditing  

Determined if, and when, the clear button displays on the component that allows the input text to be reset.


@IBInspectable public var clearButtonModeString: String  

The clear button mode representable by a String.

This property is only recommended for use in the Attributes inspector of a storyboard since enums are not @IBInspectable. Possible values are "always", "never", "whileEditing" and "unlessEditing". In code, use the clearButtonMode property instead.


public override var intrinsicContentSize: CGSize  



public override func awakeFromNib()  


public override func prepareForInterfaceBuilder()  


public override func layoutSubviews()  


@discardableResult public override func becomeFirstResponder() -> Bool  


@discardableResult public override func resignFirstResponder() -> Bool  


func add(validationRule rule: DSValidationRule)  

Adds a validation rule to be used for validating the current value.


validation​Rule DSValidation​Rule

A ValidationRule object to be used for checking a validation


func add(validationRules rules: [DSValidationRule])  

Adds an array of validation rules to be used for validating the current value.


validation​Rules [DSValidation​Rule]

A ValidationRule array to be used for checking validations


func removeAllValidationRules()  

Removes all validation rules.


func validate()  

Explicitly request validation to occur. (This is done automatically by default.)


func attachInputAccessoryView(done: Bool = true)  

Attaches a standard accessory view for this field.


done Bool

Adds a "Done" button if true