MGSwipeTableCell是一个UITableViewCell的子类,
它实现了左,右滑动展开更多按钮用来实现一些相关操作就和QQ好友列表滑动展开的按钮一样,封装的很好,动画效果也处理很到位,废话不多说,我们来看下它的简单集成
1.写一个类来继承他,和UITableView一样的使用
2.设置代理delegate,并且实现协议MGSwipeTableCellDelegate的一些方法
1 #pragma mark - MGSwipeTableCellDelegate
2
3 - (NSArray *)swipeTableCell:(MGSwipeTableCell *)cell swipeButtonsForDirection:(MGSwipeDirection)direction swipeSettings:(MGSwipeSettings *)swipeSettings expansionSettings:(MGSwipeExpansionSettings *)expansionSettings {
4 //左边
5 expansionSettings.fillOnTrigger = YES;
6 if (direction == MGSwipeDirectionLeftToRight) {
7
8 //返回的数组必须是button类型的
9 return @[[MGSwipeButton buttonWithTitle:@"哈哈" icon:nil backgroundColor:[UIColor redColor] padding: callback:^BOOL(MGSwipeTableCell * sender){
NSLog(@"Convenience callback received (left).");
return YES;
}],[MGSwipeButton buttonWithTitle:@"哈哈" icon:nil backgroundColor:[UIColor redColor] padding: callback:^BOOL(MGSwipeTableCell * sender){
NSLog(@"Convenience callback received (left).");
return YES;
}]];
}
//右边
else {
UIButton *view = [[UIButton alloc]initWithFrame:CGRectMake(, , , )];
view.userInteractionEnabled = YES;
view.backgroundColor = [UIColor yellowColor];
return @[view];
}
}
- (BOOL)swipeTableCell:(MGSwipeTableCell *)cell tappedButtonAtIndex:(NSInteger)index direction:(MGSwipeDirection)direction fromExpansion:(BOOL)fromExpansion {
NSLog(@"%ld:%ld ",index,direction);
return YES;
}
3.可以运行查看效果了