HPFloatMenu 1.1.0

HPFloatMenu 1.1.0

Quang Hoang 维护。



  • 作者
  • Hoang

HPFloatMenu

Platform Language Version License Issues Build codecov

为您的 iOS 应用提供酷动画的 HPFloatMenu,设置和使用简单!

sample

安装

CocoaPods

pod 'HPFloatMenu'

手动

HPFloatMenu 文件夹复制到您的项目中。

自定义

HPFloatMenuView 自定义

  • 动画速度
var animationSpeed: Double = 0.1
  • 菜单中每个项的空间
var spacingItem: CGFloat = 15.0
  • 菜单的位置
var position: MenuPosition = .bottomLeft
  • 叠加颜色
var colorOverlay: UIColor = UIColor(white: 0, alpha: 0.5)
  • 径向渐变颜色
var radialGradientColors: [UIColor]

浮动菜单项可自定义

  • 项目配置
public struct ItemConfigation {
    
    public var colorTitle: UIColor!
    public var colorIcon: UIColor!
    public var fontTitle: UIFont!
    public var iconSize: CGFloat!
}
  • 使用标题和图标初始化项目
init(with title: String, icon: UIImage)
  • 使用标题、图标和自定义配置初始化项目
init(with title: String, icon: UIImage, config: ItemConfigation)
  • 使用标题和配置初始化项目
init(with title: String, config: ItemConfigation) 

监测菜单状态,你可以使用 FloatMenuDelegate 使用此

func floatMenuDidOpen(_ menu: FloatMenuView)
func floatMenuDidClose(_ menu: FloatMenuView)
func floatMenuDidSelectItem(_ menu: FloatMenuView, at index: Int)

使用方法

设置

在您的文件中添加 import HPFloatMenu

lazy var floatMenuView: FloatMenuView = {
    let view = FloatMenuView(frame: .zero)
    view.delegate = self
    return view
}()

func setDefaultItems() {
   let group = FloatMenuItem(with: "Group", config: ItemConfigation(colorIcon: UIColor(hexString: "#CFCFCF")!))
   self.floatMenuView.addItem(group)

   let watch = FloatMenuItem(with: "Watch", config: ItemConfigation(colorIcon: UIColor(hexString: "#969696")!))
   self.floatMenuView.addItem(watch)

   let settings = FloatMenuItem(with: "Settings", config: ItemConfigation(colorIcon: UIColor(hexString: "#6D6C6C")!))
   self.floatMenuView.addItem(settings)
}

override func viewDidLoad() {
   super.viewDidLoad()
   self.setDefaultItems()
   self.floatMenuView.radialGradientColors = [UIColor(hexString: "#2E2E2E")!.withAlphaComponent(0.9), UIColor(hexString: "#383838")!]
}

@objc private func showMenu(_ sender: Any) {
   self.floatMenuView.showMenu(at: sender as! UIButton)
}

extension ViewController: FloatMenuDelegate {
    func floatMenuDidOpen(_ menu: FloatMenuView) {
        print("FLoat menu did open\n")
    }

    func floatMenuDidClose(_ menu: FloatMenuView) {
        print("Float menu did close\n")
    }

    func floatMenuDidSelectItem(_ menu: FloatMenuView, at index: Int) {
        print("Did select item at index \(index)\n")
        menu.dimissItems()
    }
}

所需条件

Swift 5.0

iOS 9.0+

贡献力量

欢迎Fork、补丁和其他反馈。

创建者

HPFloatMenu

Quang Hoang

博客

许可证

HPFloatMenu 在 MIT 许可下可用。更多信息请参阅许可证文件