iOS7
前言
蘋果給開放的接口只有一個刪除按鈕,如果你想要像qq那樣側(cè)滑有多個按鈕,就需要自己寫。我用scrollview寫了一個。仁者見仁,智者見智,我是用的這個。(考慮到iOS7,8以上都很簡單了)。
Demo傳送門
核心思想
用scrollview在一個cell上面進行布局,然后進行各種你所需要的操作。進行了簡單的動畫界面,如果需要自行修補吧,嘎嘎。
這里就不給代理片段了,大家看一下demo應(yīng)該都會懂。很簡單的,希望大家能給個星星哈,謝謝啦。
運行結(jié)果

結(jié)果
iOS8+
在iOS8之后,這個就好寫多了,蘋果給了一個新的接口讓我們?nèi)フ{(diào)用更改按鈕的個數(shù):
- (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{
// 設(shè)置刪除按鈕
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之上了,那么,你解放了。歡呼吧?。?!
結(jié)束
各位大俠,覺得對自己有點用的,有能力的請給個??,謝了~~~~~~~