测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可 | MIT |
发布上次发布 | 2017 年 5 月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Javal Nanda 维护。
Swift 版本的 https://github.com/dopcn/DOPDropDownMenu
易于使用的TableView风格下拉菜单。
您需要做的唯一一件事是导入 JNDropDownMenu
,创建一个实例并将其添加到您的 View
中,并符合其数据源和代理。
import JNDropDownMenu
let menu = JNDropDownMenu(origin: CGPoint(x: 0, y: 64), height: 40)
menu.datasource = self
menu.delegate = self
self.view.addSubview(menu)
只需像对 Tableview 一样实现数据源和代理即可
extension ViewController: JNDropDownMenuDelegate, JNDropDownMenuDataSource {
func numberOfColumns(in menu: JNDropDownMenu) -> NSInteger {
return 2
}
func numberOfRows(in column: NSInteger, for forMenu: JNDropDownMenu) -> Int {
switch column {
case 0:
return columnOneArray.count
case 1:
return columnTwoArray.count
default:
return 0
}
}
func titleForRow(at indexPath: JNIndexPath, for forMenu: JNDropDownMenu) -> String {
switch indexPath.column {
case 0:
return columnOneArray[indexPath.row]
case 1:
return columnTwoArray[indexPath.row]
default:
return ""
}
}
func didSelectRow(at indexPath: JNIndexPath, for forMenu: JNDropDownMenu) {
var str = ""
switch indexPath.column {
case 0:
str = columnOneArray[indexPath.row]
break
case 1:
str = columnTwoArray[indexPath.row]
break
default:
str = ""
}
label.text = str + " selected"
}
}
菜单宽度将默认为屏幕宽度。
自定义:目前可用的自定义非常有限。您可以在设置菜单数据源之前更改颜色和字体如下
let menu = JNDropDownMenu(origin: CGPoint(x: 0, y: 64), height: 40)
//customize
menu.textColor = UIColor.red
menu.cellBgColor = UIColor.green
menu.arrowColor = UIColor.black
menu.cellSelectionColor = UIColor.white
menu.textFont = UIFont.boldSystemFont(ofSize: 15.0)
menu.datasource = self
menu.delegate = self
self.view.addSubview(menu)
Example
文件夹中找到上述显示的示例。请随意创建一个拉取请求,打开一个问题或在我 Twitter 上找到我。