测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2018 年 1 月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Robert Herdzik 维护。
库提供了一种易于实现的 Android (Material Design) 浮动操作按钮的变体,适用于 iOS。您可以用它作为您应用程序的小侧边菜单。
您可以使用 Cocoapods 安装 RHSideButtons 库
pod 'RHSideButtons'
或者您可以直接将 RHSideButtons
文件夹复制到您的项目中。
您只需要实现与知名的 UIKit 设计类似的 RHSideButtonsDataSource
和 RHSideButtonsDelegate
// You need to firstly create trigger button. You can do this using block or your builder object which should conform to 'RHButtonViewConfigProtocol'
// RHTriggerButtonView allows you to change image for pressed state! 👌🏻
let triggerButton = RHTriggerButtonView(pressedImage: UIImage(named: "exit_icon")!) {
$0.image = UIImage(named: "trigger_img")
$0.hasShadow = true
}
// Then you need to create instance of SideButtons coordinator class with your View Controller view (it can be even TableView)
sideButtonsView = RHSideButtons(parentView: view, triggerButton: triggerButton)
sideButtonsView.delegate = self
sideButtonsView.dataSource = self
// When SideButtons controller is initialized properly you should set thier position in view in e.g. viewWillAppear method:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
sideBttns?.setTriggerButtonPosition(CGPoint(x: bounds.width - 85, y: bounds.height - 85))
}
… 让我们为按钮准备我们的数据模型
//Finally you should create array of buttons which will feed our dataSource and Delegate methods :) e.g.:
let button_1 = RHButtonView {
$0.image = UIImage(named: "icon_1")
$0.hasShadow = true
}
let button_2 = RHButtonView {
$0.image = UIImage(named: "icon_2")
$0.hasShadow = true
}
let button_3 = RHButtonView {
$0.image = UIImage(named: "icon_3")
$0.hasShadow = true
}
buttonsArr.appendContentsOf([button_1, button_2, button_3])
//Similar as it is in TableView, now you should reload buttons with new values
sideButtonsView.reloadButtons()
reloadButtons()
方法来重新加载按钮(
func sideButtonsNumberOfButtons(sideButtons: RHSideButtons) -> Int
func sideButtons(sideButtons: RHSideButtons, buttonAtIndex index: Int) -> RHButtonView
func sideButtons(sideButtons: RHSideButtons, didSelectButtonAtIndex index: Int)
func sideButtons(sideButtons: RHSideButtons, didTriggerButtonChangeStateTo state: RHButtonState)
如果您决定将 RHSideButtons 定位在视图的左侧,按钮将自动消失到屏幕的左侧。
例如。
sideBttns?.setTriggerButtonPosition(25, y: frame.size.height - 85))
库版本 | Swift 版本 |
---|---|
1.0 | 2.2 |
1.0.1 | 3.0 |
请查看演示项目,您可以在其中看到我认为实现这些按钮的最佳方式(在我看来