Latest 0.5.0
Homepage https://github.com/akaimo/LNFloatingActionButton
License MIT
Platforms ios 8.0, requires ARC
Frameworks UIKit, Foundation
Authors

Swift 5.0
Carthage compatible
Version
License
Platform

LNFloatingActionButton is an easily customizable Floating Action Button.

Preview

Preview gifPreview gifPreview gif

Requirements

  • Swift 5.0 or later
  • iOS 8.0 or later

Installation

Carthage

github "akaimo/LNFloatingActionButton"

CocoaPods

pod 'LNFloatingActionButton', '~> 0.5'

Usage

It is designed like UITableView.

var cells: [LNFloatingActionButtonCell] = []

let cell = LNFloatingActionButtonCell()
cell.image = UIImage(named: "action_image")
cells.append(cell)

let fab = LNFloatingActionButton()
fab.delegate = self
fab.dataSource = self
fab.closedImage = UIImage(named: "close_image")
view.addSubview(fab)

// LNFloatingActionButtonDataSource
func numberOfCells(_ floatingActionButton: LNFloatingActionButton) -> Int {
    return cells.count
}

func cellForIndex(_ index: Int) -> LNFloatingActionButtonCell {
    return cells[index]
}

// LNFloatingActionButtonDelegate
func floatingActionButton(_ floatingActionButton: LNFloatingActionButton, didSelectItemAtIndex index: Int) {
    // action ...
    floatingActionButton.close()
}

Additional settings

Floating Action Button

Button Image
fab.closedImage = UIImage(named: "close")
// default is nil
// When it is nil, display closedImage
fab.openedImage = UIImage(named: "open")

// Size of image relative to fab size
fab.internalRatio = 0.75
Change the size
fab.size = 45
Change the colors
fab.color = .white
// Change color while tapping
tab.responsible = true
fab.touchingColor = .lightGray
Overlay
fab.isBackgroundView = true
fab.backgroundViewColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5)
Button shadow
fab.shadowOffset = CGSize(width: 0.0, height: 2.0)
fab.shadowOpacity = 0.5
fab.shadowRadius = 2.0
fab.shadowPath = fab.circlePath
fab.shadowColor = .black
Reference position of cell
// default is .center
fab.cellHorizontalAlign = .left
Title position of cell
// default is .left
fab.titleLabelPosition = .right
Cell margin
// Cell to cell margin
fab.cellMargin = 10.0
// FAB to cell margin
fab.btnToCellMargin = 15.0

Floating Action Button Cell

Cell image
cell.image = UIImage(named: "")

// Size of image relative to fab size
cell.internalRatio = 0.75
Change the size
cell.size = 45
Change the colors
cell.color = .white
// Change color while tapping
cell.responsible = true
cell.touchingColor = .lightGray
Cell shadow
cell.shadowOffset = CGSize(width: 0.0, height: 2.0)
cell.shadowOpacity = 0.5
cell.shadowRadius = 2.0
cell.shadowPath = cell.circlePath
cell.shadowColor = .black

Latest podspec

{
    "name": "LNFloatingActionButton",
    "version": "0.5.0",
    "summary": "Easy to customize Floating Action Button",
    "homepage": "https://github.com/akaimo/LNFloatingActionButton",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "akaimo": "[email protected]"
    },
    "source": {
        "git": "https://github.com/akaimo/LNFloatingActionButton.git",
        "tag": "0.5.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "swift_versions": "5.0",
    "source_files": "LNFloatingActionButton/*.{swift,h,m}",
    "frameworks": [
        "UIKit",
        "Foundation"
    ],
    "requires_arc": true,
    "swift_version": "5.0"
}

Pin It on Pinterest

Share This