美文网首页
UITableView左滑图片文字设置

UITableView左滑图片文字设置

作者: 滴滴滴开门 | 来源:发表于2022-05-12 12:15 被阅读0次

    //参考了 https://www.jianshu.com/p/432b85611f50 这个的
    //设置是否可以左滑显示按钮
    -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
    {
    return YES;
    }
    -(NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    UITableViewRowAction *TopBtn =[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@" " handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
    NSLog(@"点击了置顶");
    [tableView setEditing:NO animated:YES];//点击之后的把侧滑恢复
    }];
    TopBtn.backgroundColor =[UIColor whiteColor];

    return @[TopBtn];
    

    }
    -(void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
    {
    if (@available(iOS 13.0, *)) {
    for (UIView *subView in self.PlangetaryTableView.subviews) {
    if ([subView isKindOfClass:NSClassFromString(@"_UITableViewCellSwipeContainerView")] && [subView.subviews count] >= 1) {
    UIView *swipeView = subView.subviews.firstObject;
    swipeView.backgroundColor =[UIColor clearColor];

                if (swipeView.subviews.count >= 1) {
                    UIButton *deleteButton = swipeView.subviews[0];
                    [self configDeleteButton:deleteButton];
                }
            }
        }
    }else if (@available(iOS 11.0, *)){
        for (UIView *subView in self.PlangetaryTableView.subviews) {
            if ([subView isKindOfClass:NSClassFromString(@"UITableViewWrapperView")]) {
                for (UIView *actionView in subView.subviews) {
                    if ([actionView isKindOfClass:NSClassFromString(@"UISwipeActionPullView")]) {
                        actionView.backgroundColor =[UIColor clearColor];
                        if (actionView.subviews.count >= 1) {
                            UIButton *deleteButton = actionView.subviews[0];
                            [self configDeleteButton:deleteButton];
                        }
                    }
                }
            }
        }
        
    } else {
        PlangetaryTableViewCell *cell = [self.PlangetaryTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
        for (UIView *subView in cell.subviews) {
            if ([subView isKindOfClass:NSClassFromString(@"UITableViewCellDeleteConfirmationView")] && [subView.subviews count] >= 1) {
                UIButton *deleteButton = subView.subviews[0];
                [self configDeleteButton:deleteButton];
            }
        }
    }
    

    }
    -(void)configDeleteButton:(UIButton *)button
    {
    UIButton *Top_icon =[UIButton buttonWithType:UIButtonTypeCustom];
    [Top_icon setImage:[UIImage imageNamed:@"top_icon"] forState:UIControlStateNormal];
    [button addSubview:Top_icon];

    [Top_icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.centerY.mas_equalTo(button);
    }];
    

    }

    相关文章

      网友评论

          本文标题:UITableView左滑图片文字设置

          本文链接:https://www.haomeiwen.com/subject/levsurtx.html