https://github.com/jjochen/jjfloatingactionbutton
Floating Action Button for iOS
https://github.com/jjochen/jjfloatingactionbutton
cocoapods fab floatingactionbutton ios material-design objective-c swift
Last synced: 10 months ago
JSON representation
Floating Action Button for iOS
- Host: GitHub
- URL: https://github.com/jjochen/jjfloatingactionbutton
- Owner: jjochen
- License: mit
- Created: 2017-10-27T11:58:35.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-05-16T21:53:44.000Z (over 1 year ago)
- Last Synced: 2025-04-04T10:08:35.719Z (10 months ago)
- Topics: cocoapods, fab, floatingactionbutton, ios, material-design, objective-c, swift
- Language: Swift
- Homepage: https://jjochen.github.io/JJFloatingActionButton
- Size: 17.9 MB
- Stars: 378
- Watchers: 7
- Forks: 76
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# JJFloatingActionButton
Floating Action Button for iOS
----
Features • Preview • Requirements • Installation • Usage • Author • License
- Easy to use ✓
- Fully customizable ✓
- Place with auto layout ✓
- Design in Interface Builder ✓
- RTL language support ✓
- Handles Button with single Action ✓
- Works in Swift and Objective-C Projects ✓
- Comprehensive Test Coverage ✓
- [Complete Documentation](https://jjochen.github.io/JJFloatingActionButton) ✓
- iOS 13.0+
- Xcode 14+
- Swift 5.0
### CocoaPods
[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:
```bash
gem install cocoapods
```
To integrate JJFloatingActionButton into your Xcode project using CocoaPods, specify it in your `Podfile`:
```ruby
source 'https://cdn.cocoapods.org/'
platform :ios, '13.0'
use_frameworks!
target '' do
pod 'JJFloatingActionButton'
end
```
Then, run the following command:
```bash
pod install
```
### Manually
If you prefer not to use a dependency manager, you can integrate JJFloatingActionButton into your project manually.
### Quick Start
```swift
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)
```
### Configuration
Button appearance and behavior can be customized:
```swift
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: "Balloon")) { 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
}
```
### Delegate
```swift
optional func floatingActionButtonWillOpen(_ button: JJFloatingActionButton)
optional func floatingActionButtonDidOpen(_ button: JJFloatingActionButton)
optional func floatingActionButtonWillClose(_ button: JJFloatingActionButton)
optional func floatingActionButtonDidClose(_ button: JJFloatingActionButton)
```
### Example
To run the example project, just run the following command:
```bash
pod try JJFloatingActionButton
```
### Resources
- [Documentation](https://jjochen.github.io/JJFloatingActionButton/)
Jochen Pfeiffer [https://github.com/jjochen](https://github.com/jjochen)
JJFloatingActionButton is available under the MIT license. See the LICENSE file for more info.