Skip to content

RevealingTableViewCell is a UITableViewCell that can be slided to reveal content underneath its main view.

License

Notifications You must be signed in to change notification settings

mohsinalimat/RevealingTableViewCell

 
 

Repository files navigation

RevealingTableViewCell

Travis Swift 3.0 license MIT CocoaPods CocoaPods Carthage compatible


What is it?Check it outInstallationUsage

What is it?

RevealingTableViewCell is a UITableViewCell that can be swiped to reveal content underneath its main view.
It can be set up through Interface Builder, with no code changes.
It does not provide anything other than the sliding view - it's up to you to set up any views that need be revealed.

Check it out

CocoaPods

pod try RevealingTableViewCell

(this command clones the example project in a temporary folder and opens it in Xcode)

Directly from the repo

Clone or download this repository and then open Example/RevealingTableViewCellExample.xcodeproj.

Demo video

Click to see an example

(opens in YouTube)

Installation

Requires: Swift 3, iOS 10

CocoaPods (recommended)

pod 'RevealingTableViewCell'
github "sovata8/RevealingTableViewCell"

Usage

No code changes required, everything is done in Interface Builder.
Note that this framework does not provide anything other than the sliding view - it's up to you to set up any views that need be revealed (e.g. buttons, additional information etc.).

These screenshots show how to set up your views and IBOutlets:

Step 1

Use RevealingTableViewCell (or your subclass of it) as a custom class for your tableview cell in Interface Builder.

Step 2

Inside the cell's default contentView, put a subview and connect it to the the IBOutlet uiView_mainContent. This will be the view that slides sideways to reveal some content underneath. Using AutoLayout, pin this uiView_mainContent to it's superview using constraints:

uiView_mainContent.centerX = superview.centerX
uiView_mainContent.width = superview.width
uiView_mainContent.height = superview.height
uiView_mainContent.centerY = superview.centerY

(or instead of the height and centerY constraints, you can use top and bottom constraints)

Step 3

Inside the cell's default contentView, put and connect uiView_revealedContent_left and/or uiView_revealedContent_right subviews. Pin them using AutoLayout to the corresponding sides of your cell. Fix their widths. Make sure they are behind the uiView_mainContent.

Making the cells close when needed (optional)

Usually, you would want cells to automatically close whenever you scroll the tableview, or when another cell is swiped sideways. To achieve this, use the provided tableview extension function closeAllCells(exceptThisOne:). Here is an example (from the example project):

// Close all cells when the tableview starts scrolling vertically
extension ViewController: UIScrollViewDelegate
{
    func scrollViewDidScroll(_ scrollView: UIScrollView)
    {
        self.uiTableView.closeAllCells()
    }
}
// Close all other cells when a particular cell starts being swiped
extension ViewController: RevealingTableViewCellDelegate
{
    func didStartPanGesture(cell: RevealingTableViewCell)
    {
        self.uiTableView.closeAllCells(exceptThisOne: cell)
    }
}

(of course when you are creating the cell in your cellForRowAt indexPath logic, don't forget to specify that cell.revealingCellDelegate = self)

Known issues and considerations

  • At the moment it is required that all the 'hidden' views (the ones that are behind the main view and are revealed when sliding), are in the view hierarchy of the cell at all times, even if they are never shown. This is obviously not great when performance matters.

License

This project is licensed under the terms of the MIT license. See the LICENSE file.

About

RevealingTableViewCell is a UITableViewCell that can be slided to reveal content underneath its main view.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 81.3%
  • Ruby 16.9%
  • Objective-C 1.8%