iOS改變cell的側滑顯示圖片

本文首發地址
該想法只是爲了趕工期,並且只能對一個按鈕有效果。切記切記。

有些時候要在側滑的時候顯示圖片代替文字顯示

從簡處理流程

  • 1:在使用的cell裏申明一個view一定強引用類型
  • 2:在cell初始化的函數里加載view
  • 3:重寫commitEditingStyle進行func
  • *4:在titleForDeleteConfirmationButtonForRowAtIndexPath設置寬度

看效果圖 對比一下子

修改帶圖片

設置成中文

系統默認

代碼如下

1在使用的cell裏申明一個view一定強引用類型

@property (nonatomic, strong) UIView * consoleView;

2在cell初始化的函數里加載view

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self == [super initWithStyle: style reuseIdentifier:reuseIdentifier]) {
        self.consoleView = [[UIView alloc] initWithFrame:CGRectMake(SCREENWIDTH, 0, SCREENWIDTH, 44)];
    }
    // ****這裏的高度要和你在vc裏寫的table的行高要保持一致
    self.consoleView.backgroundColor = [UIColor greenColor];
    [self.contentView addSubview:self.consoleView];
    UIButton * delBtn = [UIButton buttonWithType:UIButtonTypeCustom];

    delBtn.frame = CGRectMake(0, 0, 65, 44);
    [delBtn setImage:[UIImage imageNamed:@"cell_dele"] forState:UIControlStateNormal];

    [self.consoleView addSubview:delBtn];
    return self;
}

3 重寫commitEditingStyle進行fund

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"-----");
    //在這裏進行對數據源的操作,刷新表格
}

4設置寬度

// 設置返回的文字越長,vc裏的cell側滑的部分就越長咯
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
    return @"刪除刪除刪除刪除刪除";
}

關注洲洲哥的微信公衆號,提高技術就靠他了
這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章