iOS7
前言
苹果给开放的接口只有一个删除按钮,如果你想要像qq那样侧滑有多个按钮,就需要自己写。我用scrollview写了一个。仁者见仁,智者见智,我是用的这个。(考虑到iOS7,8以上都很简单了)。
Demo传送门
核心思想
用scrollview在一个cell上面进行布局,然后进行各种你所需要的操作。进行了简单的动画界面,如果需要自行修补吧,嘎嘎。
这里就不给代理片段了,大家看一下demo应该都会懂。很简单的,希望大家能给个星星哈,谢谢啦。
运行结果
![](https://img.haomeiwen.com/i1210430/f57cdac989176e07.png)
iOS8+
在iOS8之后,这个就好写多了,苹果给了一个新的接口让我们去调用更改按钮的个数:
- (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;
这个方法看着挺吓人的,但是反而很好写:
#pragma mark core method
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
// 设置删除按钮
UITableViewRowAction *noDeleAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"不删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
//事件
NSLog(@"不删除");
}];
//收藏
UITableViewRowAction *noLoveAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"不收藏" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
//事件
NSLog(@"不收藏");
}];
//不开心
UITableViewRowAction *noHappyAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"不开心" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
//事件
NSLog(@"不开心");
}];
noDeleAction.backgroundColor = [UIColor blueColor];
noLoveAction.backgroundColor = [UIColor purpleColor];
return @[noHappyAction,noLoveAction,noDeleAction];
}
哈哈,所以如果你的项目开始只支持iOS8之上了,那么,你解放了。欢呼吧!!!
结束
各位大侠,觉得对自己有点用的,有能力的请给个🌟,谢了~~~~~~~
网友评论