Skip to content

A library for floating menu, user can easy custom the menu with icons and text.

License

Notifications You must be signed in to change notification settings

quanghoang0101/HPFloatMenu

Repository files navigation

HPFloatMenu

Platform Language Version License Issues Build codecov

HPFloatMenu with cool animation for your iOS app, easy setup and use!

sample

Installation

CocoaPods

pod 'HPFloatMenu'

Manually

Copy the HPFloatMenu folder to your project.

Customization

HPFloatMenuView Customizable

  • speed of animation
var animationSpeed: Double = 0.1
  • space of each item in the menu
var spacingItem: CGFloat = 15.0
  • position of the menu
var position: MenuPosition = .bottomLeft
  • overlay color
var colorOverlay: UIColor = UIColor(white: 0, alpha: 0.5)
  • radial gradient color
var radialGradientColors: [UIColor]

FloatMenuItem Customizable

  • configation for item
public struct ItemConfigation {
    
    public var colorTitle: UIColor!
    public var colorIcon: UIColor!
    public var fontTitle: UIFont!
    public var iconSize: CGFloat!
}
  • init item with title and icon
init(with title: String, icon: UIImage)
  • init item with title, icon and custom configation
init(with title: String, icon: UIImage, config: ItemConfigation)
  • init item with title and configation
init(with title: String, config: ItemConfigation) 

Monitor the states of menu, you can use FloatMenuDelegate use this:

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

Usage

Setup

Add import HPFloatMenu in your file

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()
    }
}

Requirements

Swift 5.0

iOS 9.0+

Contributing

Forks, patches and other feedback are welcome.

Creator

HPFloatMenu

Quang Hoang

Blog

License

HPFloatMenu is available under the MIT license. See the LICENSE file for more info.