FloatingSideMenu
关于
自定义侧边栏,具有浮动设计。
用法
快速入门
将菜单项作为 SideMenuItem
创建。
let view1 = SideMenuItemController()
view1.view.backgroundColor = .green
let item1 = SideMenuItem(icon: nil, title: "Green Page", viewController: view1)
let view2 = SideMenuItemController()
view2.view.backgroundColor = .yellow
let item2 = SideMenuItem(icon: nil, title: "Yellow Page", viewController: view2)
用项目数组初始化菜单。
let menu = SideMenu(items: [item1, item2])
然后根据需要使用菜单。例如
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = setupSideMenu()
window!.makeKeyAndVisible()
return true
}
视图比例分配
所有框架自动按比例分配,除非有约束的视图。如果您想手动更改比例,可以使用以下变量
SideMenuItemController.proportion
- 相对于上一个框架大小的比例。
SideMenuItemController.absoluteProportion
- 与 UIScreen.main.bounds
的比例。
例如,可以在表格中使用 absoluteProportion
。
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 60 * self.absoluteProportion
}
自定义
您可轻松自定义菜单样式。
添加顶部和底部视图
let topView = TopViewController()
let bottomView = BottomViewController()
menu.topView = topView.view
menu.bottomView = bottomView.view
自定义菜单标题
通过继承 UIView
和 SideMenuItemCellDelegate
创建自定义类。
class CustomSideMenuItemCell: UIView, SideMenuItemCellDelegate {
func setData(item: SideMenuItem) {
self.title.text = item.title
}
func select(_ select: Bool) {
title.textColor = select ? UIColor.red : UIColor.black
}
static func cellHeight(stackWidth: CGFloat) -> CGFloat {
return 52
}
}
然后在菜单对象中设置它。
menu.menuItemCellClass = CustomSideMenuItemCell.self
菜单配置
SideMenu.disableViewInteraction: Bool
- 在展开时禁用视图的交互。
true
为默认值。
SideMenu.openSwipeIsEnabled: Bool
- 启用滑动展开视图。
true
为默认值。
SideMenu.closeSwipeIsEnabled: Bool
- 启用滑动折叠视图。
true
为默认值。
示例
要求
- iOS 11.0+
- Swift 4.2+
- Xcode 10.1+
安装
CocoaPods
FloatingSideMenu 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "FloatingSideMenu"
授权
FloatingSideMenu 使用 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。