Need help with AEAccordion?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

tadija
209 Stars 23 Forks MIT License 61 Commits 3 Opened issues

Description

Simple and lightweight UITableViewController with accordion effect (expand / collapse cells)

Services available

!
?

Need anything else?

Contributors list

# 20,978
Swift
Objecti...
osx
swift-f...
56 commits

Swift 4.2 Platforms iOS CocoaPods Carthage Swift Package Manager License MIT

AEAccordion

UITableViewController with accordion effect (expand / collapse cells)

Simple and lightweight solution for making accordion effect in table view controller. Show detailed content on demand.

AEAccordion

Index

Features

  • Create accordion effect in table view controller with less effort
  • Animate expansion / collapsing of cells as you want (optional)
  • Automatic scroll on cell expansion to make entire cell visible (optional)

Usage

  • Subclass
    AccordionTableViewCell
    and override
    setExpanded:animated:
    .
import AEAccordion

final class ReadmeTableViewCell: AccordionTableViewCell {

static let reuseIdentifier = "ReadmeTableViewCell"

@IBOutlet weak var headerView: HeaderView!
@IBOutlet weak var detailView: DetailView!

// MARK: Override

override func setExpanded(_ expanded: Bool, animated: Bool) {
    super.setExpanded(expanded, animated: animated)

    if animated {
        UIView.transition(with: detailView, duration: 0.3, animations: {
            self.detailView.isHidden = !expanded
        }, completion: nil)
    } else {
        detailView.isHidden = !expanded
    }
}

}

  • Subclass
    AccordionTableViewController
    and configure cell height based on
    expandedIndexPaths
    .
import AEAccordion

final class ReadmeTableViewController: AccordionTableViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    expandFirstCell()
}

func expandFirstCell() {
    let firstCellIndexPath = IndexPath(row: 0, section: 0)
    expandedIndexPaths.append(firstCellIndexPath)
}

// MARK: UITableViewDelegate

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return expandedIndexPaths.contains(indexPath) ? 200.0 : 50.0
}

}

For more details check out Sources and Example.

Installation

License

This code is released under the MIT license. See LICENSE for details.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.