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

    }

  • 相关阅读:
    The file 'MemoryStream' is corrupted! 的解决办法
    U3D包大小优化之microlib
    U3D中IOS平台泛型方法尽少使用
    {转}Unity3d+Jenkins 自动编译iOS、Android版本(U3D远程自动打包工具)
    Unity Remote 4安卓机使用指南
    2dtoolkit获取sprite像素大小的方法
    国行手机安装GOOGLE PLAY
    手机网络上YOUTUBE用fqrouter2~~
    U3D4.X版本无法安装MONODEV编辑器
    UNITY3D在IOS开发下的反射机制限制
  • 原文地址:https://www.cnblogs.com/huangzs/p/13496224.html
Copyright © 2020-2023  润新知