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];

    }

  • 相关阅读:
    PuTTY 私钥'putty/sshdss.c' 多个信息泄露漏洞
    PuTTY DSA签名远程缓冲区溢出漏洞(CVE-2013-4207)
    Apache CloudStack多个跨站脚本漏洞(CVE-2013-2136)
    phpMyAdmin 完整路径泄露漏洞3
    程序员必知的 七 种软件架构模式!
    【扩展知识】数据结构之动态内存管理机制!
    新年新气象,拼多多退出春晚红包合作,由抖音补位!
    【新年第一个程序】三子棋小游戏(C语言数组实现)
    编程开发中你必须了解的内存知识!从分配到使用直至出现Bug!
    C语言小写转大写,小写字母转换成大写字母!
  • 原文地址:https://www.cnblogs.com/huangzs/p/13496224.html
Copyright © 2011-2022 走看看