Dropdown
final class Dropdown : UIView
extension Dropdown: UITableViewDataSource, UITableViewDelegate
A Material Design dropdown in replacement for UIPickerView
.
-
The dismiss mode for a dropdown.
See moreDeclaration
Swift
enum DismissMode
-
The direction where the dropdown will show from the
See moreanchorView
.Declaration
Swift
enum Direction
-
The current visible dropdown. There can be only one visible dropdown at a time.
Declaration
Swift
weak static var VisibleDropdown: Dropdown?
-
The view to which the dropdown will displayed onto.
Declaration
Swift
weak var anchorView: AnchorView? { get set }
-
The offset point relative to
anchorView
when the dropdown is shown above the anchor view.By default, the dropdown is showed onto the
anchorView
with the top left corner for its origin, so an offset equal to (0, 0). You can change here the default dropdown origin.Declaration
Swift
var topOffset: CGPoint { get set }
-
The offset point relative to
anchorView
when the dropdown is shown below the anchor view.By default, the dropdown is showed onto the
anchorView
with the top left corner for its origin, so an offset equal to (0, 0). You can change here the default dropdown origin.Declaration
Swift
var bottomOffset: CGPoint { get set }
-
The offset from the bottom of the window when the dropdown is shown below the anchor view. Dropdown applies this offset only if keyboard is hidden.
Declaration
Swift
var offsetFromWindowBottom: CGFloat { get set }
-
The width of the dropdown.
Defaults to
anchorView.bounds.width - offset.x
.Declaration
Swift
var width: CGFloat? { get set }
-
arrowIndication.x
arrowIndication will be add to tableViewContainer when configured
Declaration
Swift
var arrowIndicationX: CGFloat? { get set }
-
Cell height
Declaration
Swift
@objc dynamic var cellHeight: CGFloat { get set }
-
Background color
Declaration
Swift
override var backgroundColor: UIColor? { get set }
-
The color of the dimmed background (behind the dropdown, covering the entire screen).
Declaration
Swift
var dimmedBackgroundColor: UIColor { get set }
-
The background color of the selected cell in the dropdown.
Changing the background color automatically reloads the dropdown.
Declaration
Swift
@objc dynamic var selectionBackgroundColor: UIColor
-
The separator color between cells.
Changing the separator color automatically reloads the dropdown.
Declaration
Swift
@objc dynamic var separatorColor: UIColor { get set }
-
The corner radius of Dropdown.
Changing the corner radius automatically reloads the dropdown.
Declaration
Swift
@objc dynamic var ddCornerRadius: CGFloat { get set }
-
Alias method for
ddCornerRadius
variable to avoid ambiguity.Declaration
Swift
@objc dynamic func setupCornerRadius(_ radius: CGFloat)
-
The masked corners of Dropdown.
Changing the masked corners automatically reloads the dropdown.
Declaration
Swift
@objc dynamic func setupMaskedCorners(_ cornerMask: CACornerMask)
-
The color of the shadow.
Changing the shadow color automatically reloads the dropdown.
Declaration
Swift
@objc dynamic var shadowColor: UIColor { get set }
-
The offset of the shadow.
Changing the shadow color automatically reloads the dropdown.
Declaration
Swift
@objc dynamic var shadowOffset: CGSize { get set }
-
The opacity of the shadow.
Changing the shadow opacity automatically reloads the dropdown.
Declaration
Swift
@objc dynamic var shadowOpacity: Float { get set }
-
The radius of the shadow.
Changing the shadow radius automatically reloads the dropdown.
Declaration
Swift
@objc dynamic var shadowRadius: CGFloat { get set }
-
The duration of the show/hide animation.
Declaration
Swift
@objc dynamic var animationduration: Double
-
The option of the show animation. Global change.
Declaration
Swift
static var animationEntranceOptions: UIView.AnimationOptions
-
The option of the hide animation. Global change.
Declaration
Swift
static var animationExitOptions: UIView.AnimationOptions
-
The option of the show animation. Only change the caller. To change all dropdown’s use the static var.
Declaration
Swift
var animationEntranceOptions: UIView.AnimationOptions
-
The option of the hide animation. Only change the caller. To change all dropdown’s use the static var.
Declaration
Swift
var animationExitOptions: UIView.AnimationOptions
-
The downScale transformation of the tableview when the Dropdown is appearing
Declaration
Swift
var downScaleTransform: CGAffineTransform { get set }
-
The color of the text for each cells of the dropdown.
Changing the text color automatically reloads the dropdown.
Declaration
Swift
@objc dynamic var textColor: UIColor { get set }
-
The color of the text for selected cells of the dropdown.
Changing the text color automatically reloads the dropdown.
Declaration
Swift
@objc dynamic var selectedTextColor: UIColor { get set }
-
The font of the text for each cells of the dropdown.
Changing the text font automatically reloads the dropdown.
Declaration
Swift
@objc dynamic var textFont: UIFont { get set }
-
The NIB to use for DropdownCells
Changing the cell nib automatically reloads the dropdown.
Declaration
Swift
var cellNib: UINib { get set }
-
The data source for the dropdown.
Changing the data source automatically reloads the dropdown.
Declaration
Swift
var dataSource: [String] { get set }
-
The localization keys for the data source for the dropdown.
Changing this value automatically reloads the dropdown. This has uses for setting accibility identifiers on the dropdown cells (same ones as the localization keys).
Declaration
Swift
var localizationKeysDataSource: [String] { get set }
-
The format for the cells’ text.
By default, the cell’s text takes the plain
dataSource
value. ChangingcellConfiguration
automatically reloads the dropdown.Declaration
Swift
var cellConfiguration: ConfigurationClosure? { get set }
-
A advanced formatter for the cells. Allows customization when custom cells are used
Changing
customCellConfiguration
automatically reloads the dropdown.Declaration
Swift
var customCellConfiguration: CellConfigurationClosure? { get set }
-
The action to execute when the user selects a cell.
Declaration
Swift
var selectionAction: SelectionClosure?
-
The action to execute when the user selects multiple cells.
Providing an action will turn on multiselection mode. The single selection action will still be called if provided.
Declaration
Swift
var multiSelectionAction: MultiSelectionClosure?
-
The action to execute when the dropdown will show.
Declaration
Swift
var willShowAction: Closure?
-
The action to execute when the user cancels/hides the dropdown.
Declaration
Swift
var cancelAction: Closure?
-
The dismiss mode of the dropdown. Default is
OnTap
.Declaration
Swift
var dismissMode: Dropdown.DismissMode { get set }
-
Creates a new instance of a dropdown. Don’t forget to setup the
dataSource
, theanchorView
and theselectionAction
at least before callingshow()
.Declaration
Swift
convenience init()
-
Creates a new instance of a dropdown.
Declaration
Swift
convenience init(anchorView: AnchorView, selectionAction: SelectionClosure? = nil, dataSource: [String] = [], topOffset: CGPoint? = nil, bottomOffset: CGPoint? = nil, cellConfiguration: ConfigurationClosure? = nil, cancelAction: Closure? = nil)
Parameters
anchorView
The view to which the dropdown will displayed onto.
selectionAction
The action to execute when the user selects a cell.
dataSource
The data source for the dropdown.
topOffset
The offset relative to
anchorView
used when displayed on above the anchor view.bottomOffset
The offset relative to
anchorView
used when displayed on below the anchor view.cellConfiguration
The format for the cells’ text.
cancelAction
The action to execute when the user cancels/hides the dropdown.
Return Value
A new instance of a dropdown customized with the above parameters.
-
Set up default appearance
Declaration
Swift
class func setupDefaultAppearance()
-
An Objective-C alias for the show() method which converts the returned tuple into an NSDictionary.
Declaration
Swift
@objc(show) func objc_show() -> NSDictionary
Return Value
NSDictionary with “canBeDisplayed” Bool, and possibly for the “offScreenHeight” Optional(CGFloat).
-
Shows the dropdown if enough height.
Declaration
Swift
@discardableResult func show(onTopOf window: UIWindow? = nil, beforeTransform transform: CGAffineTransform? = nil, anchorPoint: CGPoint? = nil) -> (canBeDisplayed: Bool, offscreenHeight: CGFloat?)
Return Value
Wether it succeed and how much height is needed to display all cells at once.
-
Hides the dropdown.
Declaration
Swift
func hide()
-
Reloads all the cells.
It should not be necessary in most cases because each change to
dataSource
,textColor
,textFont
,selectionBackgroundColor
andcellConfiguration
implicitly callsreloadAllComponents()
.Declaration
Swift
func reloadAllComponents()
-
(Pre)selects a row at a certain index.
Declaration
Swift
func selectRow(at index: Index?, scrollPosition: UITableView.ScrollPosition = .none)
-
Select rows
Declaration
Swift
func selectRows(at indices: Set<Index>?)
Parameters
indices
Selection
-
Deselect row
Declaration
Swift
func deselectRow(at index: Index?)
Parameters
index
Index
-
Deselect rows
Declaration
Swift
func deselectRows(at indices: Set<Index>?)
Parameters
indices
Indices
-
Returns the index of the selected row.
Declaration
Swift
var indexForSelectedRow: Index? { get }
-
Returns the selected item.
Declaration
Swift
var selectedItem: String? { get }
-
(Pre)selects a row at a certain index.
Declaration
Swift
@objc func selectRow(_ index: Int, scrollPosition: UITableView.ScrollPosition = .none)
-
Clear selection
Declaration
Swift
@objc func clearSelection()
-
Deselect row
Declaration
Swift
@objc func deselectRow(_ index: Int)
Parameters
index
Index
-
Selected index path
Declaration
Swift
@objc var indexPathForSelectedRow: NSIndexPath? { get }
-
Starts listening to keyboard events. Allows the dropdown to display correctly when keyboard is showed.
Declaration
Swift
@objc static func startListeningToKeyboard()