AEAccordion
  • October 14, 2023

UITableViewController with accordion effect (expand / collapse cells)

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

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


Swift Package Manager:

.Package(url: “https://github.com/tadija/AEAccordion.git”, majorVersion: 2)

Carthage:

github “tadija/AEAccordion”

CocoaPods:

pod ‘AEAccordion’

GitHub


View Github

#animation #autolayout #cocoa #cocoapod #cocoapods #cocoatouch #collection #collectionkit #collectionview #collectionviewcell #collectionviewlayout #customlayout #dynamic #expandabletableview #flowlayout #hashtag #hashtags #ibinspectable #instagram #instagramanimation #ios #iosanimation #iosdevelopment #iossdk #iosswift #iosthirdparty #lightboxalgorithm #lightviewcontroller #objectivec #swift #swiftanimation #swiftcollection #swiftimage #swiftlibrary #swiftpackagemanager #swiftui #swiftuicomponents #table #tableview #tableviewcell #taglistview #tags #tagsview #uicollectionview #uicollectionviewanimation #uicollectionviewcell #uicollectionviewflowlayout #uicollectionviewlayout #uitableview #uitableviewcell #uitableviewcocoapods #uitableviewcontroller #xcode
YOU MIGHT ALSO LIKE...
🧭 NavigationKit

NavigationKit is a lightweight library which makes SwiftUI navigation super easy to use. 💻 Installation 📦 Swift Package Manager Using Swift Package Manager, add ...

swiftui-navigation-stack

An alternative SwiftUI NavigationView implementing classic stack-based navigation giving also some more control on animations and programmatic navigation. NavigationStack Installation ...

Stinsen

Simple, powerful and elegant implementation of the Coordinator pattern in SwiftUI. Stinsen is written using 100% SwiftUI which makes it ...

SwiftUI Router

With SwiftUI Router you can power your SwiftUI app with path-based routing. By utilizing a path-based system, navigation in your app becomes ...

FlowStacks

This package takes SwiftUI's familiar and powerful NavigationStack API and gives it superpowers, allowing you to use the same API not just ...