SBDropDown
用于日期和 _ 数组的简单下拉菜单。
文档
自定义文本下拉菜单
- 要相对于
sourceView
和sourceRect
显示下拉菜单 (可选)
let strTitle = "My Title"
let arrEmements = ["Value 1", "Value 2", "Value 3"]
self.showSBDropDown(strTitle: strTitle, arrSelectedIndex: [2], arrElemets: arrEmements, sourceView: sender, key: "myKey")
其中,
- strTitle :- 是下拉菜单列表的标题。
- arrElemets :- 你正常或复杂的模型数组。
- arrSelectedIndex :- 如果有任何选中索引,则设置你的数组 []
- sourceView :- 如果没有提供
sourceRect
,则指向此视图的下拉箭头,而不是使用此sourceView.bounds
- key :- 如果需要区分其他对象,可以设置额外的键
- 之后,您必须为
SBProtocol
定义代理方法,这些方法已经在开始时确认。
configCellFor(currentIndex: Int, arrSelectedIndex: [Int], currentData: Any, cell: SBTableCell, key: Any?)
如果您提供字符串数组,则不需要设置此选项。我已经为您处理了这个。😅 其中,
- currentIndex :- 如名称所示,它是当前索引
😜 - arrSelectedIndex :- 因为这个框架也支持多选。所以它有多个选中索引。
- currentData :- 你要设置为下拉菜单的对象。
- cell :-
SBTableCell
类的表格视单元格用于数据集,可以自定义勾选图标并更改标签的对齐方式。 - key :- 如果需要区分其他对象,可以设置额外的键
例如:
// MARK:- Extension for SBTableProtocol
extension ViewController: SBTableProtocol {
func configCellFor(currentIndex: Int, arrSelectedIndex: [Int], currentData: Any, cell: SBTableCell, key: Any?) {
guard isCallSetUP else { return }
if let str = currentData as? String {
cell.lblTitle.text = str
cell.imgSelected = #imageLiteral(resourceName: "correct")
cell.isSelected(arrSelectedIndex.contains(currentIndex))
}
if let clr = currentData as? UIColor {
cell.lblTitle.backgroundColor = clr
cell.lblTitle.text = ""
cell.imgSelected = #imageLiteral(resourceName: "correct")
cell.isSelected(arrSelectedIndex.contains(currentIndex))
}
}
....
} //extension
现在第二种方法是
didSelectCell(currentIndex: Int, arrSelectedIndex: [Int], currentData: Any, key: Any?)
其中,
-
currentIndex :- 如名称所示,它是当前索引
😜 -
arrSelectedIndex :- 因为这个框架也支持多选。所以它有多个选中索引。
-
currentData :- 你要设置为下拉菜单的对象。
-
key :- 如果需要区分其他对象,可以设置额外的键
当用户点击下拉列表时,将调用此方法,该方法与表格视图didSelect方法触发的方式相同
最后一个下拉代理方法如下:
btnSelectSBProtocolPressed(arrSelectedIndex: [Int], arrElements: [Any], key: Any?)
其中,
-
arrSelectedIndex :- 因为这个框架也支持多选。所以它有多个选中索引。
-
arrElemets :- 在开始时发送的正常或复杂模型数组。
-
key :- 如果需要区分其他对象,可以设置额外的键
当用户点击选择按钮时,将调用此方法。
- (可选) 下拉箭头方向
您可以按以下方式更改下拉箭头方向,
SBDropDown.shared.arrowDirection = .down
或者
SBDropDown.shared.arrowDirection = [.up, .down]
-
(可选) 选择按钮属性...
显示或隐藏SBDropDown.shared.isShowSelectButton = true // false
。更改标题SBDropDown.shared.strSelectBtnTitle = "My New Title"
。更改宽度SBDropDown.shared.cgSelectButtonWidth = 180
。更改或标题颜色SBDropDown.shared.selectBtnColor = UIColor.blue
。更改或背景颜色SBDropDown.shared.selectBGBtnColor = UIColor.white
。 -
选择类型(默认为
Multi Selection
):更改此需要设置SBDropDown.shared.isMultiSelect = true // false
-
要禁用双击,设置
SBDropDown.shared.isClearOnDoubleTab = false
日期和时间下拉菜单
- 以下是使用日期和时间下拉菜单的方式,
self.showDatePicker(sourceView: sender)
或者
self.showSBDatePicker(strTitle: "Select DOB", currentDate: Date(), minDate: nil, maxDate: nil, sourceView: sender, sourceRect: sender.bounds)
- 您还可以修改在dropdown段中显示的时间和水印格式,例如
SBDropDown.shared.strTimeFormatter = "HH:mm a"
SBDropDown.shared.strDateFormatter = "dd-MM-yyyy"
上面的格式是默认的
- 为名为
SBDateProtocol
的协议提供了3个可选代理方法如下,
didSBDateValueChanged(date: Date)
当用户更改日期选择器值时提供。
btnSBSelectPressed(date: Date)
当用户点击Select
按钮时调用此方法。
btnSBSelectDateOption(type: SBDateEnum)
当用户点击日期、时间或日期时间时也会调用此方法
需求
- iOS 10.0+
- Xcode 10.2+
- Swift 5+
安装
CocoaPods 是 Cocoa 项目的依赖管理器。有关使用和安装说明,请访问他们的网站。要使用 CocoaPods 将 SBDropDown 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它。
pod 'SBDropDown'
许可证
SBDropDown遵循MIT许可证发布。《查看许可证》以获取详细信息。
注意:- 在示例应用程序中已删除pod,请在使用之前安装它。谢谢。