在使用tableviewCell 时不少会遇到 编辑删除 一般UI 设计师为了展示其设计功底,会自定义一些icon ,然后系统的编辑状态就没发满足要求,想着在系统代码逻辑不变的情况 去尽量少修改代码,想到那按钮一定是cell subviews 遍历其subview 去更改属性(下面有效果对比图)
核心代码
1 首先自定义cell 命名MyCollectionCell
// Copyright © 2016年THJ. All rights reserved.
//
#import"MyCollectionCell.h"
@implementationMyCollectionCell
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[supersetSelected:selectedanimated:animated];
// Configure the view for the selected state
}
- (void)layoutSubviews
{
[superlayoutSubviews];
//侧滑的效果
for(UIView*subViewinself.subviews) {
if([NSStringFromClass([subViewclass])isEqualToString:@"UITableViewCellDeleteConfirmationView"]) {
((UIView*)[subView.subviewsfirstObject]).backgroundColor=UIColorFromRGBA(0xfcf9f9,1);// [UIColor colorWithRed:249/255.0 green:247/255.0 blue:247/255.0 alpha:1];
[((UIButton*)[subView.subviewslastObject])setTitleColor:[UIColorredColor]forState:UIControlStateNormal];
}
//隐藏cell选中状态的时候分割线
if([NSStringFromClass([subViewclass])isEqualToString:@"_UITableViewCellSeparatorView"]) {
[subViewremoveFromSuperview];
}
//自定义左侧选择按钮的image
if(self.selected) {
if([NSStringFromClass([subViewclass])isEqualToString:@"UITableViewCellEditControl"]) {
for(UIView* subView1insubView.subviews) {
if([subView1isKindOfClass:[UIImageViewclass]]) {
UIImageView* tempImageVie = (UIImageView*)subView1;
tempImageVie.image= [UIImageimageNamed:@"cellSelectedImage"];
}
}
}
}
}
}