Class
DSSelect
@IBDesignable public final class DSSelect: UIView, DSSelectControl
An Enterprise-styled option selection. This should be used when a user needs to select a value from a set of options.
For storyboards, add a UIView and change the class name to DSSelect.
Initialize and set properties as needed.
let select = DSSelect()
let options = [
DSSelectOption(data: "medical", label: "Medical"),
DSSelectOption(data: "dental", label: "Dental"),
DSSelectOption(data: "vision", label: "Vision")
]
select.labelText = "Choose Your Coverage"
select.helperText = "You will be signed up after configuration"
select.options = options
select.value = options[0]
Use a DSSelectDelegate to detect when its tapped so you can navigate to the options list:
func selectTapped(_ select: DSSelect) {
select.showOptionSelection(on: navigationController)
}
Relationships
Conforms To
DSSelectControl
A protocol extension for select controls.
UIView
Initializers
init(frame:)
public override init(frame: CGRect)
Properties
selectDelegate
@IBOutlet public weak var selectDelegate: DSSelectDelegate?
The delegate which receives updates on the DSSelect's state.
isEnabled
@IBInspectable public var isEnabled: Bool = true
Returns true if the component is enabled and allows changing the value.
helperText
@IBInspectable public var helperText: String?
The text to be displayed as helper (below the label) to clarify what the field's value represents.
options
public var options: [DSSelectOption] = []
The ordered list of valid values that can be selected for this field.
validationRules
public var validationRules
The array of ValidationRule objects to be used for validating the current state of the field.
validationState
public private(set) var validationState: DSValueValidationState = .unvalidated
validation state of the current value.
Methods
awakeFromNib()
public override func awakeFromNib()
prepareForInterfaceBuilder()
public override func prepareForInterfaceBuilder()
layoutSubviews()
public override func layoutSubviews()
add(validationRule:)
func add(validationRule rule: DSValidationRule)
Adds a validation rule to be used for validating the current value.
Parameters
Name | Type | Description |
---|---|---|
validationRule | DSValidationRule |
A ValidationRule object to be used for checking a validation |
add(validationRules:)
func add(validationRules rules: [DSValidationRule])
Adds an array of validation rules to be used for validating the current value.
Parameters
Name | Type | Description |
---|---|---|
validationRules | [DSValidationRule] |
A ValidationRule array to be used for checking validations |
validate()
@discardableResult func validate() -> DSValidationRule?
Returns the validation status of the current value based on the current validation rules.