A simple fully customizable dropdown.
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift
compiler.
Once you have your Swift package set up, add SwiftDropdown to the dependencies
value of your Package.swift
.
dependencies: [
.package(url: "https://github.com/giuseppebruno/SwiftDropdown.git", .upToNextMajor(from: "1.0.0"))
]
Add a UIView
from the Storyboard and subclass as SwiftDropdown
or create a SwiftDropdown
view from code.
import SwiftDropdown
...
let dropdown = SwiftDropdown()
dropdown.placeholderText = "Select..."
dropdown.options = ["Option 1", "Option 2", "Option 3"]
You can customize the Dropdown as follow:
boxBackgroundColor
: Dropdown box background color. Default: whiteplaceholderFont
: Dropdown box text font. Default: System fontplaceholderColor
: Dropdown box text color. Default: blackarrowImage
: Dropdown arrow image.arrowPosition
: Arrow position. Default: rightcornerRadius
: Box and dropdown corner radiusborderWidth
: Box and dropdown border width. Default: 1borderColor
: Box and dropdown border color. Default: blackdisableArrowAnimation
: Disable arrow animation. Default: true
dropdownHeight
: Dropdown height. By default will be calculated automatically.itemsRowHeight
: Dropdown items row height. Default: 44itemsFont
: Dropdown items text font. Default: System fontitemsTextColor
: Dropdown items text color. Default: blackdisableTapToDismiss
: Disable tap outside the dropdown to dismiss itself. Default: falsedropdownExtraSpace
: Space between the box and the dropdown. Default: 8itemsBackgroundColor
: Dropdown items background color. Default: whiteshowSelectedItemCheckmark
: Show checkmark for selected item. Default: truecheckmarkColor
: Selected item checkmark color. Default: system bluehighlightSelectedItem
: Highlight selected item. Default: falseselectedItemBackgroundColor
: Selected item background color. Default: system blueselectedItemTextColor
: Selected item text color. Default: whitedropdownSeparatorStyle
: Dropdown item separator style
selectedIndex
: Current selected index. If setted, the dropdown will show the item as selected.selectedItem
: Current selected item
class MyViewController: UIViewController, SwiftDropdownDelegate {
...
dropdown.delegate = self
...
func dropdownItemSelected(index: Int, item: String) {}
We welcome all contributions. If you found a bug, feel free to open an issue. If you want to contribute, submit a pull request.
- ⭐️ Star the repo
- 🗣 Share the repo with your friends
SwiftDropdown is developed by Giuseppe Bruno.
SwiftDropdown is released under the MIT license. See LICENSE for details.