Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vkt0r/accordionswift
The best way of implement an accordion menu using an UITableView in Swift
https://github.com/vkt0r/accordionswift
accordion cocoapods swift tableview xcode
Last synced: 10 days ago
JSON representation
The best way of implement an accordion menu using an UITableView in Swift
- Host: GitHub
- URL: https://github.com/vkt0r/accordionswift
- Owner: Vkt0r
- License: mit
- Created: 2015-02-05T19:36:05.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-03-17T09:44:37.000Z (over 3 years ago)
- Last Synced: 2024-10-12T09:23:07.303Z (25 days ago)
- Topics: accordion, cocoapods, swift, tableview, xcode
- Language: Swift
- Homepage:
- Size: 4.77 MB
- Stars: 172
- Watchers: 11
- Forks: 31
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
----------------
_An accordion/dropdown menu to integrate in your projects. This library is protocol oriented, type safe and the new version is inspired in [JSQDataSourcesKit](https://github.com/jessesquires/JSQDataSourcesKit) by Jesse Squires_.
| | Main Features |
----------|-----------------
📱 | Compatible with iPhone / iPad
🔨 | Fully customizable cells
🚒 | Supports device rotation
🔥 | Written completely in Swift## Requirements 💥
- iOS 10.0+
- Xcode 10.2+## Installation
### CocoaPods
[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:
```bash
$ gem install cocoapods
```> CocoaPods 1.1.0+ is required to build AccordionSwift 2.0.0+.
To integrate AccordionSwift into your Xcode project using CocoaPods, specify it in your `Podfile`:
```ruby
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!target '' do
pod 'AccordionSwift', '~> 2.0.0'
end
```Then, run the following command:
```bash
$ pod install
```### Carthage
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate AccordionSwift into your Xcode project using Carthage, specify it in your `Cartfile`:
```ogdl
github "Vkt0r/AccordionSwift" ~> 2.0.0
```## Usage ✨
After importing the framework, the library can be used in a `UITableViewController` or a `UIViewController` and offers full customization of the cells and data source:```swift
import UIKit
import AccordionSwiftclass AccordionViewController: UIViewController {
// MARK: - IBOutlets
@IBOutlet weak var tableView: UITableView!
// MARK: - Typealias
typealias ParentCellModel = Parent
typealias ParentCellConfig = CellViewConfig
typealias ChildCellConfig = CellViewConfig
// MARK: - Properties
/// The Data Source Provider with the type of DataSource and the different models for the Parent and Chidl cell.
var dataSourceProvider: DataSourceProvider, ParentCellConfig, ChildCellConfig>?
// MARK: - UIViewController
override func viewDidLoad() {
super.viewDidLoad()
configDataSource()
navigationItem.title = "World Cup 2018"
}
}
```
The above example shows how to define a `CellViewConfig` for the parent and child cells respectively and how to define the `Parent` model.```swift
/// Defines a cell config type to handle a UITableViewCell
public protocol CellViewConfigType {
// MARK: Associated types
/// The type of elements backing the collection view or table view.
associatedtype Item
/// The type of views that the configuration produces.
associatedtype Cell: UITableViewCell
// MARK: Methods
func reuseIdentiferFor(item: Item?, indexPath: IndexPath) -> String
@discardableResult
func configure(cell: Cell, item: Item?, tableView: UITableView, indexPath: IndexPath) -> Cell
}
```Another step is to define the `DataSourceProvider` in charge of handling the data source and the `CellViewConfig` for each cell.
The `DataSourceProvider` exposes the `numberOfExpandedParentCells` attribute which can be used to change the behavior of the accordion to only have a `single` item open at once or to have `multiple` items open at any given time. Take note that the default behavior is to have multiple items open.For a more detailed guide please see the [Example](https://github.com/Vkt0r/AccordionSwift/tree/master/Example) project.
## Screenshots
#### Example of multiple cells open at a time
#### Example of single cells open at a time
## TODO
- [ ] Add unit tests for the library.
- [ ] Add CircleCI integration.## Feedback
## I've found a bug, or have a feature request
Please raise a [GitHub issue](https://github.com/Vkt0r/AccordionMenu/issues). 😱
## Interested in contributing?
Great! Please launch a [pull request](https://github.com/Vkt0r/AccordionMenu/pulls). 👍
---------------------------------------
License:
=================
The MIT License. See the [LICENSE file](LICENSE) for more information.