RVS_AutofillTextField
@IBDesignable
@MainActor
open class RVS_AutofillTextField : UITextField
extension RVS_AutofillTextField: UITableViewDataSource
extension RVS_AutofillTextField: UITableViewDelegate
This class extends the standard UITextField widget to provide a realtime “dropdown” menu of possible
autocomplete choices (in a table and modal-style screen).
The dropdown is always displayed below the text field, and is attached to the main window root view (so it appears over everything else). It is not modal.
If the user selects a value from the table, that entire string is entered into the text field, and the dropdown is dismissed.
The dropdown is dismissed whenever focus leaves the text item.
When focus is set to the text field, the current text is evaluated, and a dropdown may appear, if required.
If the autofill functionality is not available, or is explicitly deactivated, the text item behaves exactly like a standard UITextField.
NB: When assigning a delegate, the caller needs to be a UITextFieldDelegate,
even if they are not using any of the delegate functionality.
This is because we “piggyback” on the built-in delegate.
This also means that the delegate must be an NSObject.
-
The default value for case sensitivity (OFF)
Declaration
Swift
@MainActor public static let defaultIsCaseSensitive: Bool -
The default value for wildcards before (OFF)
Declaration
Swift
@MainActor public static let defaultIsWildcardBefore: Bool -
The default value for wildcards after (ON)
Declaration
Swift
@MainActor public static let defaultIsWildcardAfter: Bool -
The default value for maximum count (5)
Declaration
Swift
@MainActor public static let defaultMaximumCount: Int
-
When the table comes up, this will be the color. The default is the standard system color, with a reduced alpha.
Declaration
Swift
@IBInspectable @MainActor public var tableBackgroundColor: UIColor { get set } -
This is the text color to use in the table. Default is label color.
Declaration
Swift
@IBInspectable @MainActor public var tableTextColor: UIColor { get set } -
The minimum width of the table. It will be at least this wide, and will follow the width of the edit text item, if it is bigger. It will also never go beyond the trailing edge of the screen.
Declaration
Swift
@IBInspectable @MainActor public var minimumTableWidthInDisplayUnits: CGFloat { get set } -
This is the maximum number of results to be returned. Default is 5. If -1, then there is no limit.
Declaration
Swift
@IBInspectable @MainActor public var maximumAutofillCount: Int { get set } -
This is a “circuit breaker” for the autofill capability. Default is on. If Off, the autofill will not be shown.
Declaration
Swift
@IBInspectable @MainActor public var isAutoFillOn: Bool { get set } -
This specifies whether or not matches are case-blind (default), or case-sensitive (true).
Declaration
Swift
@IBInspectable @MainActor public var isCaseSensitive: Bool { get set } -
If true (default is false), then the match is made at the end of the string.
Declaration
Swift
@IBInspectable @MainActor public var isWildcardBefore: Bool { get set } -
If true (default is true), then the match is made at the beginning of the string.
Declaration
Swift
@IBInspectable @MainActor public var isWildcardAfter: Bool { get set } -
This allows us to assign an explicit “container” view for the popover. Default is nil. If not provided, the main window, itself, is used.
Declaration
Swift
@MainActor public weak var containerView: UIView? -
This is the data source for this widget. Be aware that this is a strong reference. This is not inspectable, and must be assigned programmatically.
Declaration
Swift
@MainActor public var dataSource: RVS_AutofillTextFieldDataSource? -
This is the font to use. It must be set programmatically. By default, it is system 20.
Declaration
Swift
@MainActor public var tableFont: UIFont
-
Called to close the table view, and, possibly, resign as first responder.
Declaration
Swift
@MainActor public func closeTableViewAndResignFirstResponder() -
If the table is open, when this is called, it will do a reloadData().
Declaration
Swift
@MainActor public func refreshTable()
-
Called to hide or show the field. We override, so we make sure that the table gets hidden, when we are.
Declaration
Swift
@MainActor public override var isHidden: Bool { get set } -
This makes sure that we create or move the table, if we are no longer the focus.
Declaration
Swift
@discardableResult @MainActor public override func becomeFirstResponder() -> Bool -
This makes sure that we remove the table, if we are no longer the focus.
Declaration
Swift
@discardableResult @MainActor public override func resignFirstResponder() -> Bool -
Called when we trigger a layout. We use this to register our callback.
Declaration
Swift
@MainActor public override func layoutSubviews() -
Called when we are being removed from our superview. We remove the callback (just to be sure -belt and suspenders).
Declaration
Swift
@MainActor public override func removeFromSuperview()
-
This returns the number of rows to display in the autofill table.
Declaration
Swift
@MainActor public func tableView(_: UITableView, numberOfRowsInSection: Int) -> IntReturn Value
The number of rows to display.
-
This returns one cell of the table, with the specific autofill suggestion. The text is attributed, so the match is made slightly more prominent than the unmatched text.
Declaration
Swift
@MainActor public func tableView(_ inTableView: UITableView, cellForRowAt inIndexPath: IndexPath) -> UITableViewCellParameters
inTableViewThe table view.
inIndexPathThe index of the cell to be returned (section will always be 0).
Return Value
A new, simple, default cell, with an attributed text content.
-
This reacts to the user selecting a suggested text item. It sets the edit field text to the selected text, and closes the table.
Declaration
Swift
@MainActor public func tableView(_ inTableView: UITableView, didSelectRowAt inIndexPath: IndexPath)Parameters
inTableViewThe table view.
inIndexPathThe index of the selected row,
View on GitHub