LNFloatingActionButton
LNFloatingActionButton is an easily customizable Floating Action Button.
Preview
Requirements
- Swift 5.0 or later
- iOS 8.0 or later
Installation
Carthage
github "akaimo/LNFloatingActionButton"
CocoaPods
pod 'LNFloatingActionButton', '~> 0.5.1'
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