JVMenu
使用Swift编写的简单iOS菜单。目前只支持纵向模式,可能还会考虑扩展它以支持横向模式。决定分享,因为我正在将其用于我的一个应用中。
示例
要运行示例项目,请克隆仓库,然后从示例目录运行pod install
。
使用
您可以将任何对象调整为符合 JVMenuProtocol,就像在 BaseMenuViewController 中展示的那样。然后,您只需遵守协议中的函数。
extension BaseMenuViewController: JVMenuProtocol {
func selectedMenuItem(row: Int) {
// push or do any work based on menu selection...
print(row)
}
var data: JVMenuDataModel {
return JVMenuDataModel(items)
}
}
第一个函数 selectedMenuItem 将被调用,根据行指示哪个菜单对象被选中。然后,类型为 JVMenuDataModel 的变量 data 将提供对菜单的所有定制,如:菜单项、背景颜色、行高、字体、文字颜色和表格分隔线颜色。您可以使用默认实现,并指定菜单项,就像在 BaseMenuViewController 中展示的那样...
private var items: [JVMenuItem] {
return [JVMenuItem(icon: UIImage(named: "icons8-settings")!, title: "First Menu 1"),
JVMenuItem(icon: UIImage(named: "icons8-settings")!, title: "Second Menu 2"),
JVMenuItem(icon: UIImage(named: "icons8-settings")!, title: "Third Menu 3"),
JVMenuItem(icon: UIImage(named: "icons8-settings")!, title: "Forth Menu 4"),
JVMenuItem(icon: UIImage(named: "icons8-settings")!, title: "Fifth Menu 5"),
JVMenuItem(icon: UIImage(named: "icons8-settings")!, title: "Sixth Menu 6")]
}
此 JVMenuItem 数组将包含要用于菜单的每个图标及其标题。
最后,您可以调用一些默认实现,例如 showMenu() 或 hideMenu(如果需要,因为菜单在选中菜单选项或通过手势 dismissed 后会自动隐藏)。
注意:此菜单被添加到 UIWindown,并且是一个 singleton 实例。
需求
当前仅支持最新版本的iOS 13.4。抱歉! :/
安装
JVMenu 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile。
pod 'JVMenu'
作者
JV17, [邮箱地址保护]
许可证
JVMenu遵循MIT许可证。有关更多信息,请参阅LICENSE文件。