控件处理之左滑cell

UITableView自定义系统左滑Cell菜单

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {

    }

}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {

    return UITableViewCellEditingStyleDelete;

}

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {

    return @"标记为\n已回访";

}

// 设置显示多个按钮

- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewRowAction * deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"屏蔽用户" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {

    }];

    deleteRowAction.backgroundColor = [UIColor redColor];

    UITableViewRowAction * topRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"取消关注" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {

    }];

    topRowAction.backgroundColor = [UIColor blueColor];

    return @[deleteRowAction,topRowAction];

}

在cell中自定义样式

- (void)layoutSubviews

{

    [super layoutSubviews];

   

    // 去掉隐式动画

    [CATransaction begin];

    [CATransaction setDisableActions:YES];

    [self setupSlideBtn];

    [CATransaction commit];

}

// 设置左滑菜单按钮的样式

- (void)setupSlideBtn

{

    for (UIView *subView in self.subviews) {

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

           

            // 屏蔽用户

            UIView *smsContentView = subView.subviews[0];

           

           

            for (UIView *smsView in smsContentView.subviews) {

                [smsView removeAllSubviews];

            }

           

            UIImageView *smsImage = [[UIImageView alloc] init];

            smsImage.image = [UIImage imageNamed:@"UserView_follow2"];

            smsImage.frame = smsContentView.bounds;

            [smsContentView addSubview:smsImage];

           

           

            // 取消关注

            UIView *messageContentView = subView.subviews[1];

           

            for (UIView *messageView in messageContentView.subviews) {

                [messageView removeAllSubviews];

            }

           

            UIImageView *messageImage = [[UIImageView alloc] init];

            messageImage.image = [UIImage imageNamed:@"UserView_follow1"];

            messageImage.frame = messageContentView.bounds;

            [messageContentView addSubview:messageImage];

           

        }

    }

}

使用panCell自定义左滑菜单

1、创建 cell 继承 PanTableViewCell 

2、添加PanTableViewCellDelegate协议方法

3、实现协议方法

#import "PanCellButton.h"

- (NSArray<PanCellButton *> *)panTableViewCell:(PanTableViewCell *)cell tableView:(UITableView *)tableView rightPanCellButtonsAtIndexPath:(NSIndexPath *)indexPath{

   

    PanCellButton *removeFollowUserButton = [[PanCellButton alloc] initWithTitle:nil image:[UIImage imageNamed:@"UserView_follow1"] onClickCallback:^(UIButton *panButton) {

        [self CancelFollowAction];

    }];

   

    PanCellButton *hiddenUserButton = [[PanCellButton alloc] initWithTitle:nil image:[UIImage imageNamed:@"UserView_follow2"] onClickCallback:^(UIButton *panButton) {

        [self ShieldingUser];

    }];

   

    return @[hiddenUserButton,removeFollowUserButton];

}

效果图

菜单的大小可以自定义

下载使用

https://github.com/githubze/panCell

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1.nav1.navigationBar.barStyle=UIBarStyleBlack; //改变导航栏背景颜...
    SadMine阅读 1,636评论 1 4
  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 2,547评论 1 14
  • 版权声明:未经本人允许,禁止转载. 1. TableView初始化 1.UITableView有两种风格:UITa...
    萧雪痕阅读 2,919评论 2 10
  • 一群人像一股胡乱颓圮的色彩融入了黑白分明的大纲,从进门那一刻橘右京就开始恍惚起来。 人是从什么时候有恍惚这种感觉的...
    丁二二丁阅读 328评论 0 1
  • 平时很少去医院,倒不是身体多好,是嫌麻烦。没想到去了一趟医院,发生很多麻烦事。 这几个月鼻炎越来越严重,朋友严正警...
    傲骨前妻阅读 242评论 0 1