设置UITableView背景透明/监听cell左边的删除按钮的点击事件

    _tableView = [[UITableView alloc] init];
    _tableView.delegate   = self;
    _tableView.dataSource = self;
  
_tableView.frame = CGRectMake(kZero, 66, kScreenW, kScreenH - 66 - 70);
  //设置列表为透明背景
    UIImage *image = [MusicManager createImageWithColor:[UIColor clearColor]];
    _tableView.backgroundView  = [[UIImageView alloc] initWithImage:image];
    _tableView.backgroundColor = [UIColor clearColor];
    
#pragma mark    设置UITableView背景的代理方法
-(void)tableView:(UITableView*)tableView  willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath
{
    [cell setBackgroundColor:[UIColor clearColor]];
}

#pragma mark   点击cell左边的删除按钮时触发
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
 
    //获取当前处于删除状态的cell
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    //获取cell中所有的子控件
    NSArray *labelArray = cell.contentView.subviews;
    for (UIImageView *view in labelArray) {
        if (view.tag == 3) {//向右的图片
            CGRect temp = view.frame;
            temp.origin.x = 255;
            view.frame = temp;
        }
    }
    return @"删除";
}

原文地址:https://www.cnblogs.com/hw140430/p/3889580.html