What is it? • Check it out • Installation • Usage
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.
pod try RevealingTableViewCell
(this command clones the example project in a temporary folder and opens it in Xcode)
Clone or download this repository and then open Example/RevealingTableViewCellExample.xcodeproj
.
(opens in YouTube)
Requires: Swift 3
, iOS 10
CocoaPods (recommended)
pod 'RevealingTableViewCell'
github "sovata8/RevealingTableViewCell"
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:
Use RevealingTableViewCell
(or your subclass of it) as a custom class for your tableview cell in Interface Builder.
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)
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
.
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
)
- 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.
This project is licensed under the terms of the MIT license. See the LICENSE file.