• cell左滑加删除置顶功能 iOS


    需求:开发下面这种样式,列表左滑有置顶和删除功能

    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {

        return YES;

    }

     

    -(UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {

        UIContextualAction *delete = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"删除".ntes_localized handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {

            [tableView setEditing:NO animated:YES];

            completionHandler(YES);

        }];

        UIContextualAction *top = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"置顶" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {

            NSLog(@"%@",@"置顶");

            [tableView setEditing:NO animated:YES];

            completionHandler(YES);

        }];

        top.backgroundColor = UIColorFromRGB(0xEEF7FF);

        

        UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:@[delete,top]];

        //禁止滑动到底直接执行第一个按钮的事件

        config.performsFirstActionWithFullSwipe=NO;

        return config;

    }

    修改左滑按钮的样式

    - (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath {

        UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];

        [CATransaction begin];

        [CATransaction setDisableActions:YES];

        for (UIView * subView in cell.superview.subviews) {

            if ([subView isKindOfClass:NSClassFromString(@"UISwipeActionPullView")]) {

                for (UIView * sonView in subView.subviews) {

                    if ([sonView isKindOfClass:NSClassFromString(@"UISwipeActionStandardButton")]) {

                        UIButton *aBtn = (UIButton *)sonView;

                        aBtn.titleLabel.font = kFont(14);

                        if (![aBtn.currentTitle isEqualToString:@"删除"]) {

                            [aBtn setTitleColor:UIColorFromRGB(0x3072F6) forState:UIControlStateNormal];

                        }

                    }

                }

            }

        }

        [CATransaction commit];

    }

  • 相关阅读:
    App架构经验总结
    通过C语言程序改动控制台的背景和前景颜色
    java实现读取yaml文件,并获取值
    java 实现yaml 数据转json与map
    yaml标记语言的简介
    重新学习之spring第二个程序,配置AOP面向切面编程
    重新学习之spring第一个程序,配置IOC容器
    重新学习Spring之核心IOC容器的底层原理
    hibernate之xml映射文件关系维护,懒加载,级联
    hibernate映射xml文件配置之一对多,多对多
  • 原文地址:https://www.cnblogs.com/huangzs/p/13496224.html
Copyright © 2020-2023  润新知