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) {
    UIView.setAnimationsEnabled(false)
    tableView.beginUpdates()
    tableView.endUpdates()
    UIView.setAnimationsEnabled(true)
}

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

UITextInputTraits
UIView

Initializers

init(rendering​Type:​)

public init(renderingType: DSTextFieldRenderingType = .cell)  

Properties

text​Field​Delegate

@IBOutlet public weak var textFieldDelegate: DSTextFieldDelegate?  

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

is​Multiline

@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.

is​Enabled

@IBInspectable public var isEnabled: Bool = true  

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

prefix​Text

@IBInspectable public var prefixText: String?  

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

label​Text

@IBInspectable public var labelText: String?  

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

helper​Text

@IBInspectable public var helperText: String?  

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

is​Secure​Text

@IBInspectable public var isSecureText: Bool = false  

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

shows​Show​Hide​Button​With​Secure​Text

@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.

text

@IBInspectable public var text: String?  

The text entered into the DSTextField.

validation​State

public var validationState: DSValueValidationState  

The current validation state based on validation rules you have.

applies​Background​Color​ToSuperview

@IBInspectable public var appliesBackgroundColorToSuperview: Bool = false  

Automatically makes superview background color match when enabled/disabled

input​Mask

public var inputMask: DSInputMask?  

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

raw​Text

public var rawText: String  

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

unprefixed​Text

public var unprefixedText: String  

Returns the text as it appears in DSTextField minus prefixing.

validation​Rules

public var validationRules  

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

is​Valid

public var isValid: Bool  

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

return​Key​Type

public var returnKeyType: UIReturnKeyType = .default  

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

keyboard​Type

public var keyboardType: UIKeyboardType = .default  

Specifies the type of keyboard for the field

text​Content​Type

public var textContentType: UITextContentType! = nil  

Specifies the semantic meaning for the field

autocorrection​Type

public var autocorrectionType: UITextAutocorrectionType = .default  

Specifies if words should be autocorrected as typed

spell​Checking​Type

public var spellCheckingType: UITextSpellCheckingType = .default  

Specifies if words should be spell checked as typed

autocapitalization​Type

public var autocapitalizationType: UITextAutocapitalizationType = .sentences  

Specifies how capitalization happens as typed

accessibility​Label

public override var accessibilityLabel: String?  

Specifies the accessibilityLabel for the entire field

text​View

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.)

text​Field

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.)

rendering​Type

public var renderingType: DSTextFieldRenderingType = .cell  

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

rendering​Type​String

@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.

clear​Button​Mode

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.

clear​Button​Mode​String

@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.

intrinsic​Content​Size

public override var intrinsicContentSize: CGSize  

Methods

awake​From​Nib()

public override func awakeFromNib()  

prepare​For​Interface​Builder()

public override func prepareForInterfaceBuilder()  

layout​Subviews()

public override func layoutSubviews()  

become​First​Responder()

@discardableResult public override func becomeFirstResponder() -> Bool  

resign​First​Responder()

@discardableResult public override func resignFirstResponder() -> Bool  

add(validation​Rule:​)

func add(validationRule rule: DSValidationRule)  

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

Parameters

validation​Rule DSValidation​Rule

A ValidationRule object to be used for checking a validation

add(validation​Rules:​)

func add(validationRules rules: [DSValidationRule])  

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

Parameters

validation​Rules [DSValidation​Rule]

A ValidationRule array to be used for checking validations

remove​All​Validation​Rules()

func removeAllValidationRules()  

Removes all validation rules.

validate()

func validate()  

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

attach​Input​Accessory​View(done:​)

func attachInputAccessoryView(done: Bool = true)  

Attaches a standard accessory view for this field.

Parameters

done Bool

Adds a "Done" button if true