LNFloatingActionButton 0.5.1

LNFloatingActionButton 0.5.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2019年10月
SPM支持 SPM

akaimo 维护。



  • akaimo

LNFloatingActionButton

Swift 5.0 Carthage compatible Version License Platform

LNFloatingActionButton 是一个易于自定义的浮动操作按钮。

预览

Preview gifPreview gifPreview gif

需求

  • Swift 5.0 或更高版本
  • iOS 8.0 或更高版本

安装

Carthage

github "akaimo/LNFloatingActionButton"

CocoaPods

pod 'LNFloatingActionButton', '~> 0.5.1'

使用方法

它类似于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()
}

附加设置

浮动操作按钮

按钮图片
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
更改大小
fab.size = 45
更改颜色
fab.color = .white
// Change color while tapping
tab.responsible = true
fab.touchingColor = .lightGray
叠加
fab.isBackgroundView = true
fab.backgroundViewColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5)
按钮阴影
fab.shadowOffset = CGSize(width: 0.0, height: 2.0)
fab.shadowOpacity = 0.5
fab.shadowRadius = 2.0
fab.shadowPath = fab.circlePath
fab.shadowColor = .black
单元格参考位置
// default is .center
fab.cellHorizontalAlign = .left
单元格标题位置
// default is .left
fab.titleLabelPosition = .right
单元格边距
// Cell to cell margin
fab.cellMargin = 10.0
// FAB to cell margin
fab.btnToCellMargin = 15.0

浮动操作按钮单元格

单元格图片
cell.image = UIImage(named: "")

// Size of image relative to fab size
cell.internalRatio = 0.75
调整大小
cell.size = 45
更改颜色
cell.color = .white
// Change color while tapping
cell.responsible = true
cell.touchingColor = .lightGray
单元格阴影
cell.shadowOffset = CGSize(width: 0.0, height: 2.0)
cell.shadowOpacity = 0.5
cell.shadowRadius = 2.0
cell.shadowPath = cell.circlePath
cell.shadowColor = .black