iOS改變cell的側滑顯示圖片
阿新 • • 發佈:2019-01-10
本文首發地址
該想法只是為了趕工期,並且只能對一個按鈕有效果。切記切記。
有些時候要在側滑的時候顯示圖片代替文字顯示
從簡處理流程
- 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 @"刪除刪除刪除刪除刪除";
}
關注洲洲哥的微信公眾號,提高技術就靠他了