- Notifications
You must be signed in to change notification settings - Fork1.1k
An easy to use UITableViewCell subclass that allows to display swippable buttons with a variety of transitions.
License
MortimerGoro/MGSwipeTableCell
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
MGSwipeTableCell is an easy to use UITableViewCell subclass that allows to display swipeable buttons with a variety of transitions.
This library is compatible with all the different ways to create a UITableViewCell: system predefined styles, programmatically created cells, cells loaded from a xib and prototype cells within a storyboard. You can use autolayout if you want.
Works on iOS >= 5.0. Tested on all iOS versions on iPhone and iPad: iOS 7, iOS 8, iOS 9, iOS 10, iOS 11, iOS 12, iOS 13, iOS 14.
SeeMGSwipeTableCell.h
header file for a complete overview of the capabilities of the class.
SeeMailAppDemo
for a complete project which mimics Apple's Mail App (written in Objective-C)
SeeMailAppDemoSwift
for a complete project which mimics Apple's Mail App (Written in Swift)
SeeSpotifyDemo
for a complete project which mimics Spotify App swipe style
SeeMGSwipeDemo
for a complete project where you can test the variety of transitions on a real device/simulator.
You can use CocoaPods to include MGSwipeTableCell into you project:
pod 'MGSwipeTableCell'
You can use Carthage to include MGSwipeTableCell into your project. Just add this dependency to your Cartfile:
github "MortimerGoro/MGSwipeTableCell"
You can use Swift Package Manager to include MGSwipeTableCell into you project:
.package(url: "https://github.com/MortimerGoro/MGSwipeTableCell.git", from: "1.6.0")
Integrating MGSwipeTableCell in your project is very easy. Basically, you only have to inherit from MGSwipeTableCell instead of UITableViewCell, or directly instantiate MGSwipeTableCell instances with iOS predefined cell styles. You can layout your cell content as you are used to do, MGSwipeTableCell doesn't force you to change layouts.
Here is a example of a MGSwipeTableCell using iOS predefined styles. You can set an array of buttons to cell.leftButtons and/or cell.rightButtons properties. MGSwipeButton is a convenience class, you are not forced to use it. You can use your own UIButtons or UIViews. You can configure transitions (and swipe thresholds) with the leftSwipeSettings and/or rightSwipeSettings properties
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{staticNSString * reuseIdentifier =@"programmaticCell"; MGSwipeTableCell * cell = [self.tableViewdequeueReusableCellWithIdentifier:reuseIdentifier];if (!cell) { cell = [[MGSwipeTableCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:reuseIdentifier]; } cell.textLabel.text =@"Title"; cell.detailTextLabel.text =@"Detail text"; cell.delegate = self;//optional//configure left buttons cell.leftButtons = @[[MGSwipeButtonbuttonWithTitle:@""icon:[UIImageimageNamed:@"check.png"]backgroundColor:[UIColorgreenColor]], [MGSwipeButtonbuttonWithTitle:@""icon:[UIImageimageNamed:@"fav.png"]backgroundColor:[UIColorblueColor]]]; cell.leftSwipeSettings.transition = MGSwipeTransition3D;//configure right buttons cell.rightButtons = @[[MGSwipeButtonbuttonWithTitle:@"Delete"backgroundColor:[UIColorredColor]], [MGSwipeButtonbuttonWithTitle:@"More"backgroundColor:[UIColorlightGrayColor]]]; cell.rightSwipeSettings.transition = MGSwipeTransition3D;return cell;}
func tableView(_ tableView:UITableView, cellForRowAt indexPath:IndexPath)->UITableViewCell{letreuseIdentifier="programmaticCell"varcell= tableView.dequeueReusableCell(withIdentifier: reuseIdentifier, for: indexPath)as!MGSwipeTableCell cell.textLabel!.text="Title" cell.detailTextLabel!.text="Detail text" cell.delegate=self //optional //configure left buttons cell.leftButtons=[MGSwipeButton(title:"", icon:UIImage(named:"check.png"), backgroundColor:.green),MGSwipeButton(title:"", icon:UIImage(named:"fav.png"), backgroundColor:.blue)] cell.leftSwipeSettings.transition=.rotate3D //configure right buttons cell.rightButtons=[MGSwipeButton(title:"Delete", backgroundColor:.red),MGSwipeButton(title:"More",backgroundColor:.lightGray)] cell.rightSwipeSettings.transition=.rotate3Dreturn cell}
In order to listen for button click events you can implement the optional MGSwipeTableCellDelegate, or if you are too lazy to do that, the MGSwipeButton class comes with a convenience block callback ;)
[MGSwipeButtonbuttonWithTitle:@"More"backgroundColor:[UIColorlightGrayColor]callback:^BOOL(MGSwipeTableCell *sender) {NSLog(@"Convenience callback for swipe buttons!");}]
MGSwipeButton(title:"Delete", backgroundColor:.red){(sender: MGSwipeTableCell!)-> Bool inprint("Convenience callback for swipe buttons!")returntrue}
MGSwipeTableCellDelegate is an optional delegate to configure swipe buttons or to receive triggered actions or another events. Buttons can be configured inline when the cell is created instead of using this delegate, but using the delegate improves memory usage since buttons are only created on demand.
@protocolMGSwipeTableCellDelegate <NSObject>@optional/** * Delegate method to enable/disable swipe gestures * @return YES if swipe is allowed **/-(BOOL)swipeTableCell:(MGSwipeTableCell*)cellcanSwipe:(MGSwipeDirection)direction;/** * Delegate method invoked when the current swipe state changes @param state the current Swipe State @param gestureIsActive YES if the user swipe gesture is active. No if the uses has already ended the gesture **/-(void)swipeTableCell:(MGSwipeTableCell*)celldidChangeSwipeState:(MGSwipeState)stategestureIsActive:(BOOL)gestureIsActive;/** * Called when the user clicks a swipe button or when a expandable button is automatically triggered * @return YES to autohide the current swipe buttons **/-(BOOL)swipeTableCell:(MGSwipeTableCell*)celltappedButtonAtIndex:(NSInteger)indexdirection:(MGSwipeDirection)directionfromExpansion:(BOOL)fromExpansion;/** * Delegate method to setup the swipe buttons and swipe/expansion settings * Buttons can be any kind of UIView but it's recommended to use the convenience MGSwipeButton class * Setting up buttons with this delegate instead of using cell properties improves memory usage because buttons are only created in demand * @param swipeTableCell the UITableViewCell to configure. You can get the indexPath using [tableView indexPathForCell:cell] * @param direction The swipe direction (left to right or right to left) * @param swipeSettings instance to configure the swipe transition and setting (optional) * @param expansionSettings instance to configure button expansions (optional) * @return Buttons array **/-(NSArray*)swipeTableCell:(MGSwipeTableCell*)cellswipeButtonsForDirection:(MGSwipeDirection)directionswipeSettings:(MGSwipeSettings*)swipeSettingsexpansionSettings:(MGSwipeExpansionSettings*)expansionSettings;@end
Buttons are not expandable by default. You can set up expandable buttons using cell.leftExpansion and cell.rightExpansion properties
Expandable button events are triggered automatically when the user ends the swipe gesture and the expansion is active (configurable via threshold value). Triggered expandable buttons can bounce back to their initial position or fill the entire UITableViewCell, you can select the desired animation using fillOnTrigger property.
@interfaceMGSwipeExpansionSettings:NSObject/** index of the expandable button (in the left or right buttons arrays)*/@property (nonatomic,assign)NSInteger buttonIndex;/** if true the button fills the cell on trigger, else it bounces back to its initial position*/@property (nonatomic,assign)BOOL fillOnTrigger;/** Size proportional threshold to trigger the expansion button. Default value 1.5*/@property (nonatomic,assign) CGFloat threshold;@end
MGSwipeTableCell supports rounded corners. Example:
cell.layer.cornerRadius =50cell.backgroundColor = UIColor.graycell.clipsToBounds =truecell.swipeBackgroundColor = UIColor.gray
The MIT License (MIT)
Copyright (c) 2014 Imanol Fernandez @MortimerGoro
Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.
About
An easy to use UITableViewCell subclass that allows to display swippable buttons with a variety of transitions.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.