zoukankan      html  css  js  c++  java
  • 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];

    }

  • 相关阅读:
    js—初始的二维数组是一个,3行4列的数组。将其转换为4行3列的二维数组
    js_求1—10000的完数
    JS——输入一个日期判断该日期为当年的第几天
    JS——打印倒三角和正三角
    Java内存机制和内存地址
    deepin下搭建基于github和hexo的个人博客
    URL and URI 的 比较
    Cannot use this in a static context
    java项目获取文件路径总结
    利用exe4j制作exe文件
  • 原文地址:https://www.cnblogs.com/huangzs/p/13496224.html
Copyright © 2011-2022 走看看