JJFloatingActionButton 3.0.1

JJFloatingActionButton 3.0.1

测试已测试
语言语言 SwiftSwift
许可 MIT
发布上次发布Apr 2024
SPM支持 SPM

Jochen Pfeiffer 维护。




  • Jochen Pfeiffer

JJFloatingActionButton

iOS 的浮动操作按钮


Swift 5.0 Version License Platform Build Status codecov Code Climate Documentation Contributions Welcome

特性预览要求安装用法作者许可证

特性

  • 易于使用 ✓
  • 完全可定制 ✓
  • 使用自动布局放置 ✓
  • 在 Interface Builder 中设计 ✓
  • 支持从右到左的语言 ✓
  • 处理具有单个动作的按钮 ✓
  • 在 Swift 和 Objective-C 项目中工作 ✓
  • 全面的测试覆盖 ✓
  • 完整文档

预览

Preview Basics Preview Configuration

Preview Circular Preview Single Item

需求

  • iOS 9.0+
  • Xcode 10.2+
  • Swift 5.0

安装

CocoaPods

CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它

$ gem install cocoapods

要使用 CocoaPods 将 JJFloatingActionButton 集成到您的 Xcode 项目中,请在您的 Podfile 中指定它

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'JJFloatingActionButton'
end

然后,运行以下命令

$ pod install

手动

如果您不想使用依赖管理器,您可以手动将 JJFloatingActionButton 集成到您的项目中。

用法

快速开始

let actionButton = JJFloatingActionButton()

actionButton.addItem(title: "item 1", image: UIImage(named: "First")?.withRenderingMode(.alwaysTemplate)) { item in
  // do something
}

actionButton.addItem(title: "item 2", image: UIImage(named: "Second")?.withRenderingMode(.alwaysTemplate)) { item in
  // do something
}

actionButton.addItem(title: "item 3", image: nil) { item in
  // do something
}

view.addSubview(actionButton)
actionButton.translatesAutoresizingMaskIntoConstraints = false
actionButton.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -16).isActive = true
actionButton.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -16).isActive = true

// last 4 lines can be replaced with
// actionButton.display(inViewController: self)

配置

按钮外观和行为可以自定义

actionButton.handleSingleActionDirectly = false
actionButton.buttonDiameter = 65
actionButton.overlayView.backgroundColor = UIColor(white: 0, alpha: 0.3)
actionButton.buttonImage = UIImage(named: "Dots")
actionButton.buttonColor = .red
actionButton.buttonImageColor = .white
actionButton.buttonImageSize = CGSize(width: 30, height: 30)

actionButton.buttonAnimationConfiguration = .transition(toImage: UIImage(named: "X"))
actionButton.itemAnimationConfiguration = .slideIn(withInterItemSpacing: 14)

actionButton.layer.shadowColor = UIColor.black.cgColor
actionButton.layer.shadowOffset = CGSize(width: 0, height: 1)
actionButton.layer.shadowOpacity = Float(0.4)
actionButton.layer.shadowRadius = CGFloat(2)

actionButton.itemSizeRatio = CGFloat(0.75)
actionButton.configureDefaultItem { item in
    item.titlePosition = .trailing

    item.titleLabel.font = .boldSystemFont(ofSize: UIFont.systemFontSize)
    item.titleLabel.textColor = .white
    item.buttonColor = .white
    item.buttonImageColor = .red

    item.layer.shadowColor = UIColor.black.cgColor
    item.layer.shadowOffset = CGSize(width: 0, height: 1)
    item.layer.shadowOpacity = Float(0.4)
    item.layer.shadowRadius = CGFloat(2)
}

actionButton.addItem(title: "Balloon", image: UIImage(named: "Baloon")) { item in
    // Do something
}

let item = actionButton.addItem()
item.titleLabel.text = "Owl"
item.imageView.image = UIImage(named: "Owl")
item.buttonColor = .black
item.buttonImageColor = .white
item.buttonImageColor = CGSize(width: 30, height: 30)
item.action = { item in
    // Do something
}

委托

optional func floatingActionButtonWillOpen(_ button: JJFloatingActionButton)
optional func floatingActionButtonDidOpen(_ button: JJFloatingActionButton)
optional func floatingActionButtonWillClose(_ button: JJFloatingActionButton)
optional func floatingActionButtonDidClose(_ button: JJFloatingActionButton)

示例

要运行示例项目,只需执行以下命令

$ pod try JJFloatingActionButton

资源

作者

乔钦·费费 https://github.com/jjochen

许可

JJFloatingActionButton 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。