iOS DropDown
支持搜索功能的iOS下拉菜单
这是一个支持iOS下拉菜单的Swift库
支持搜索并返回正确索引
定制
hideOptionWhenSelect = false
示例
要运行示例项目,请克隆仓库,然后先从示例目录运行 pod install
。
功能
- 简单的UITextField扩展,使用简单,我们可以访问UITextField的所有属性
- 可以启用或禁用下拉搜索
- 可以更改列表的背景颜色和选定颜色
- 可以更改列表的最大高度和每行的高度
安装
CocoaPods
使用CocoaPods。iOSDropDown通过CocoaPods提供。要安装它,请简单地将以下行添加到您的Podfile中
- 将
pod 'iOSDropDown'
添加到您的Podfile中。 - 通过运行
pod install
安装pod。 - 在构建阶段 > 链接二进制库中添加
iOSDropDown.framework
- 在您想要使用它的.swift文件中添加
import iOSDropDown
Carthage
使用Carthage。
- 创建一个名为
Cartfile
的文件。 - 添加行
github "jriosdev/iOSDropDown"
。 - 运行
carthage update
。 - 将构建好的
iOSDropDown.framework
拖到您的Xcode项目中。
手册
只需克隆并添加以下Swift文件到您的项目中
- iOSDropDown.swift
✨
基本用法Storyboard方法
只需将UITextField添加到您的ViewController中,并连接至@IBOutlet - DropDown类
@IBOutlet weak var dropDown : DropDown!
// The list of array to display. Can be changed dynamically
dropDown.optionArray = ["Option 1", "Option 2", "Option 3"]
//Its Id Values and its optional
dropDown.optionIds = [1,23,54,22]
// Image Array its optional
dropDown.ImageArray = [👩🏻🦳,🙊,🥞]
// The the Closure returns Selected Index and String
dropDown.didSelect{(selectedText , index ,id) in
self.valueLabel.text = "Selected String: \(selectedText) \n index: \(index)"
}
或
代码方法
let dropDown = DropDown(frame: CGRect(x: 110, y: 140, width: 200, height: 30)) // set frame
// The list of array to display. Can be changed dynamically
dropDown.optionArray = ["Option 1", "Option 2", "Option 3"]
// Its Id Values and its optional
dropDown.optionIds = [1,23,54,22]
// Image Array its optional
dropDown.ImageArray = [👩🏻🦳,🙊,🥞]
// The the Closure returns Selected Index and String
dropDown.didSelect{(selectedText , index ,id) in
self.valueLabel.text = "Selected String: \(selectedText) \n index: \(index)"
}
}
其他选项
动作
dropDown.showList() // To show the Drop Down Menu
dropDown.hideList() // To hide the Drop Down Menu
闭包
listWillAppear() {
//You can Do anything when iOS DropDown willAppear
}
listDidAppear() {
//You can Do anything when iOS DropDown listDidAppear
}
listWillDisappear() {
//You can Do anything when iOS DropDown listWillDisappear
}
listDidDisappear() {
//You can Do anything when iOS DropDown listDidDisappear
}
🖌
自定义iOSDropDown您可以自定义以下下拉菜单属性:
isSearchEnabled
: 可以开启或关闭在下拉菜单中。默认值是true
hideOptionsWhenSelect
: 选择某一选项时,隐藏列表。默认值是true
selectedRowColor
:下拉列表中选中行的颜色。默认值为.cyan
rowBackgroundColor
:下拉列表的背景颜色。默认值为.white
listHeight
:列表的最大高度。默认值是150
rowHeight
:列表中行的高度。默认值是30
selectedIndex
:用于提前选择列表中的任何一个项目arrowSize
:箭头的大小。默认值是15
arrowColor
:箭头的颜色。默认值是.black
checkMarkEnabled
:用于选择行的复选标记启用。默认值是true
textColor
:可以更改下拉列表的选中文本颜色semanticContentAttribute
:用于RTL或LTR的语义属性除了TextField属性外,所有其他属性都可以在下拉列表中使用
,例如alignment
、font
、textColor
、semanticContentAttribute
等
注意
1.After Update the pod just do clean your buld folder
Product > Clean Build Folder .
作者
✨ ✨ 如果喜欢我的项目,请在GitHub上给我一个STAR✨ ✨
如果这个项目帮助您减少了开发时间,您能提供一杯咖啡吗:)
Jishnu Raj T,[email protected]
许可协议
iOSDropDown遵循MIT许可协议。有关更多信息,请参阅LICENSE文件。