DropdownMenu 是一个用于 Swift 的 navigationController 的下拉菜单,如果存在 navigationController,它可以关联到任何位置
特性
- 下拉菜单
- 上拉菜单
支持单元格类型
- 仅文本单元格
- 图文单元格
- 高亮单元格
- 选中单元格
- 详情附件单元格
需求
- iOS 8.0
- Xcode 7.3+
沟通
- 如果您 需要帮助,请添加问题。或者发送电子邮件到 [email protected]
安装
**嵌入式框架需要至少iOS 8的部署目标
CocoaPods
CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它
$ gem install cocoapods
要使用 CocoaPods 将 DropdownMenu 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
target '<Your Target Name>' do
pod 'TBDropdownMenu'
end
然后,运行以下命令
$ pod install
Carthage
Carthage 是一个集中式依赖管理器,它构建您的依赖并为您提供二进制框架。
您可以使用以下命令使用 Homebrew 安装 Carthage
$ brew update
$ brew install carthage
要使用 Carthage 将 DropdownMenu 集成到您的 Xcode 项目中,请在您的 Cartfile
中指定它
github "teambition/DropdownMenu"
运行 carthage update
命令来构建框架
最后,您需要手动设置您的 Xcode 项目来添加 DropdownMenu 框架。
在您的应用程序目标的“常规”设置选项卡的“链接的框架和库”部分,将您想从磁盘上的 Carthage/Build 文件夹中拖放的每个框架拖放到那里。
在您的应用程序目标的“构建阶段”设置选项卡上,点击“+”图标并选择“新运行脚本阶段”。创建一个包含以下内容的运行脚本
/usr/local/bin/carthage copy-frameworks
并将要使用的框架的路径添加到“输入文件”下
$(SRCROOT)/Carthage/Build/iOS/DropdownMenu.framework
有关如何使用 Carthage 的更多信息,请参阅其 项目页面
使用方法
将框架导入您的类
CocoaPods
import TBDropdownMenu
Carthage
import DropdownMenu
下拉菜单
为您的行为添加代码
无章节
func showMenu(sender: UIBarButtonItem) {
let item1 = DropdownItem(title: "NO Image")
let item2 = DropdownItem(image: UIImage(named: "file")!, title: "File")
let item3 = DropdownItem(image: UIImage(named: "post")!, title: "Post", style: .Highlight)
let item4 = DropdownItem(image: UIImage(named: "post")!, title: "Event", style: .Highlight, accessoryImage: UIImage(named: "accessory")!)
let items = [item1, item2, item3, item4]
let menuView = DropdownMenu(navigationController: navigationController!, items: items, selectedRow: selectedRow)
menuView.delegate = self
menuView.showMenu()
}
有章节
@IBAction func showMenu(_ sender: UIBarButtonItem) {
let item1 = DropdownItem(title: "NO Image")
let item2 = DropdownItem(image: UIImage(named: "file")!, title: "File")
let item3 = DropdownItem(image: UIImage(named: "post")!, title: "Post", style: .highlight)
let item4 = DropdownItem(image: UIImage(named: "post")!, title: "Event", style: .highlight, accessoryImage: UIImage(named: "accessory")!)
let section0 = DropdownSection(sectionIdentifier: "Teambition", items: [item1, item2])
let section1 = DropdownSection(sectionIdentifier: "Space", items: [item3, item4])
let menuView = DropdownMenu(navigationController: navigationController!, sections: [section0, section1], selectedIndexPath: selectedIndexPath)
menuView?.delegate = self
menuView?.showMenu()
}
处理委托
extension ViewController: DropdownMenuDelegate {
func dropdownMenu(dropdownMenu: DropdownMenu, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print("DropdownMenu didselect \(indexPath.row)")
}
}
上拉菜单
为您的行为添加代码
@IBAction func dropUpAction(_ sender: UIBarButtonItem) {
let item1 = DropdownItem(title: "NO Image")
let item2 = DropdownItem(image: UIImage(named: "file")!, title: "File")
let item3 = DropdownItem(image: UIImage(named: "post")!, title: "Post", style: .highlight)
let item4 = DropdownItem(image: UIImage(named: "post")!, title: "Event", style: .highlight, accessoryImage: UIImage(named: "accessory")!)
let data = [item1, item2, item3, item4]
items = [data]
let menuView = DropUpMenu(items: data, selectedRow: 0, bottomOffsetY: self.tabBarController?.tabBar.frame.height ?? 0)
menuView.delegate = self
menuView.showMenu()
}
处理委托
extension ViewController: DropUpMenuDelegate {
func dropUpMenu(_ dropUpMenu: DropUpMenu, didSelectRowAt indexPath: IndexPath) {
let alertConroller = UIAlertController(title: "Nice", message: "DropUpMenu didselect \(indexPath.row) text:\(items[indexPath.section][indexPath.row].title)", preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alertConroller.addAction(okAction)
present(alertConroller, animated: true) {
print("Display success")
}
}
func dropUpMenuCancel(_ dropUpMenu: DropUpMenu) {
print("select cancel")
}
}
详细信息请查看演示
协议
DropdownMenu以MIT许可证发布。