MGSwipeTableCell的使用(UItabelCell 滑动拉出多个按钮)
来源:互联网 发布:多功能数据采集器 编辑:程序博客网 时间:2024/04/28 08:01
侧滑UITableViewCell展示多个可操作按钮是iOS开发中常用到的一个功能。这里有个非常强大的开源库:MGSwipeTableCell,可以实现此功能。其效果如下图所示:
引入工程
■CocoaPods 引入
建议使用,没有使用过CocoaPods的童鞋可以参照大神唐巧的这篇文章用CocoaPods做iOS程序的依赖管理。
■手动引入
下载地址MGSwipeTableCell。
使用
可以直接用MGSwipeTableCellcell,也可以继承于MGSwipeTableCell,下面是一个使用的例子:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString * reuseIdentifier = @"programmaticCell"; MGSwipeTableCell * cell = [self.tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; if (!cell) { cell = [[MGSwipeTableCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier]; } cell.textLabel.text = @"Title"; cell.detailTextLabel.text = @"Detail text"; cell.delegate = self; //optional //configure left buttons cell.leftButtons = @[[MGSwipeButton buttonWithTitle:@"" icon:[UIImage imageNamed:@"check.png"] backgroundColor:[UIColor greenColor]], [MGSwipeButton buttonWithTitle:@"" icon:[UIImage imageNamed:@"fav.png"] backgroundColor:[UIColor blueColor]]]; cell.leftSwipeSettings.transition = MGSwipeTransition3D; //configure right buttons cell.rightButtons = @[[MGSwipeButton buttonWithTitle:@"Delete" backgroundColor:[UIColor redColor]], [MGSwipeButton buttonWithTitle:@"More" backgroundColor:[UIColor lightGrayColor]]]; cell.rightSwipeSettings.transition = MGSwipeTransition3D; return cell;}
cell.leftButtons 和 cell.rightButtons都是一个数组,可以动态填写按。
cell.rightSwipeSettings.transition是侧滑的动画,有多重选择。
为了监听点击按钮的事件,你有两种方法:
■实现MGSwipeTableCellDelegate
■定义MGSwipeButton按钮时有方便使用的block回调:
[MGSwipeButton buttonWithTitle:@"More" backgroundColor:[UIColor lightGrayColor] callback:^BOOL(MGSwipeTableCell *sender) { NSLog(@"Convenience callback for swipe buttons!"); }];
Delegate
MGSwipeTableCellDelegate 是用来配置滑动按钮或接收触发的动作或另一个事件的可选的委托。按钮可以在cell创建的时候就嵌入进去而不用使用delegate,不过使用delegate可以改善内存的使用,因为按钮只有在使用的时候才创建。
- (BOOL)swipeTableCell:(MGSwipeTableCell*)cell canSwipe:(MGSwipeDirection)direction;
决定是否可以使用划动手势。
- (void)swipeTableCell:(MGSwipeTableCell*)cell didChangeSwipeState:(MGSwipeState)state gestureIsActive:(BOOL) gestureIsActive;
当前swipe state状态改变时使用。
- (BOOL)swipeTableCell:(MGSwipeTableCell*)cell tappedButtonAtIndex:(NSInteger)index direction:(MGSwipeDirection)direction fromExpansion:(BOOL) fromExpansion;
用户点击按钮时回调。
- (NSArray*)swipeTableCell:(MGSwipeTableCell*)cell swipeButtonsForDirection:(MGSwipeDirection)direction swipeSettings:(MGSwipeSettings*)swipeSettings expansionSettings:(MGSwipeExpansionSettings*)expansionSettings;
设置swipe button 和 swipe/expansion 的设置。
可扩展的按钮(Expandable buttons)
按钮默认是不可以扩展的。你可以使用cell.leftExpansion 和 cell.rightExpansion 来设置可可扩展的按钮。
可扩展的按钮事件是当用户完成滑动手势时自动触发的。扩展程度是动态的(通过threshold的值来设置)。触发的可扩展按钮可以恢复到其初始位置或填充整个 UITableViewCell,您可以使用 fillOnTrigger 属性选择所需的动画。
@interface MGSwipeExpansionSettings: 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
冻僵的企鹅(简书作者)
原文链接:http://www.jianshu.com/p/25908a61f849
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
- MGSwipeTableCell的使用(UItabelCell 滑动拉出多个按钮)
- MGSwipeTableCell 滑动失效 解决办法
- iOS UITableViewCell的”滑动出现多个按钮
- iOS UITableViewCell的"滑动出现多个按钮"
- jquery插件:点击拉出的右侧滑动菜单
- iOS UITableViewCell"滑动出现多个按钮"
- 滑动UITableViewCell出现多个按钮
- iOSUITableViewCell滑动显示多个按钮
- iOS tableView滑动出现多个按钮
- Android使用最简单的方式实现ListView 拉出回弹效果,阻尼效果(一)
- IOS 开发使用UITableView 实现滑动 删除等多个按钮
- 使用js实现按钮的滑动效果
- ios8 tableView设置滑动删除时显示多个按钮
- ios8 tableView设置滑动删除时显示多个按钮
- 1.IOS TableView滑动显示多个按钮
- ios8 tableView设置滑动删除时显示多个按钮
- iOS开发:多个按钮点击滑动效果
- UITableViewCell左右侧滑动出现多个按钮
- C++之函数模板
- app开发总结 1 - 接口设计
- dll和so文件区别与构成
- 蓝牙 BCSP 解析 源码分析
- zigbee学习重点资料的摘录1
- MGSwipeTableCell的使用(UItabelCell 滑动拉出多个按钮)
- 移动端屏幕自适应
- PXC在线增加节点
- 一个“403”问题的产生及解决
- app开发总结 2 - 开发规范
- hdu_5274_Dylans loves tree(树剖)
- opengl 实现最小化的画图系统
- pb调用http的简单方法
- java 深拷贝 实现方式