iOSDropDown
iOS 15 update
这是一个支持 iOS 中下拉菜单的 Swift 库
观看视频:
要运行示例项目,请克隆存储库,然后首先从示例目录运行pod install
。
Swift Package Manager 是一个用于自动分发 Swift 代码的工具,并集成到swift
编译器中。
设置完 Swift 包后,将 iOSDropDown 添加为依赖项就像将其添加到Package.swift
的dependencies
值中一样简单。
dependencies: [
. package ( url : " https://github.com/jriosdev/iOSDropDown.git " , . upToNextMajor ( from : " 0.4.0 " ) )
]
使用 CocoaPods。 iOSDropDown 可通过 CocoaPods 获得。要安装它,只需将以下行添加到您的 Podfile 中:
pod 'iOSDropDown'
添加到您的Podfile中。pod install
安装 pod。iOSDropDown.framework
import iOSDropDown
使用迦太基。
Cartfile
。github "jriosdev/iOSDropDown"
。carthage update
。iOSDropDown.framework
拖到您的 Xcode 项目中。只需克隆以下 Swift 文件并将其添加到您的项目中:
只需将 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
}
自定义过滤功能
// overridable function for filter action
func searchFilter ( text : String , searchText : String ) -> Bool {
// you can add custom filter fuctions as your need, like other than english ..etc
}
您可以自定义下拉列表的这些属性:
isSearchEnabled
:您可以在 DropDown 上启用或禁用。默认值为true
hideOptionsWhenSelect
:此选项可在单击选项一项时隐藏列表。默认值为true
selectedRowColor
: DropDown 中选定行项目的颜色默认值为.cyan
rowBackgroundColor
: DropDown 的颜色默认值为.white
listHeight
:列表的最大高度。默认值为150
rowHeight
:列表中列表的高度。默认值为30
selectedIndex
:用于预选择列表中的任何项目arrowSize
:箭头的大小。默认值为15
arrowColor
:箭头的颜色。默认值为.black
checkMarkEnabled
:勾选“标记已启用”以选择行。默认值为true
textColor
:您可以更改 DropDown 选定的文本颜色semanticContentAttribute
:RTL或LTR的语义属性All Other TextField Properties are available with DropDown
例如alignment
、 font
、 textColor
、 semanticContentAttribute
...等 1.After Update the pod just do clean your buld folder
Product > Clean Build Folder .
Jishnu Raj T,[email protected]
iOSDropDown 在 MIT 许可下可用。有关详细信息,请参阅许可证文件。