1. 程式人生 > >Table 編輯editing下,左側對勾自定義替換

Table 編輯editing下,左側對勾自定義替換

//
//  EditTableViewCell.m
//  TableviewEditCell
//
//  Created by yangsu on 2016/12/22.
//  Copyright © 2016年 WuYuqiu. All rights reserved.
//

#import "EditTableViewCell.h"

@implementation EditTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    
    [super setEditing:editing animated:animated];
    for (UIControl *control in self.subviews){
        if ([control isMemberOfClass:NSClassFromString(@"UITableViewCellEditControl")]){
            for (UIView *v in control.subviews)
            {
                if ([v isKindOfClass: [UIImageView class]]) {
                    UIImageView *img=(UIImageView *)v;
                    if (!self.selected) {
                        img.image=[UIImage imageNamed:@"editCellUnSelected"];
                    }
                }
            }
        }
    }
}

-(void)layoutSubviews {
    
    for (UIControl *control in self.subviews){
        if ([control isMemberOfClass:NSClassFromString(@"UITableViewCellEditControl")]){
            for (UIView *v in control.subviews)
            {
                if ([v isKindOfClass: [UIImageView class]]) {
                    UIImageView *img=(UIImageView *)v;
                    if (self.selected) {
                        img.image=[UIImage imageNamed:@"editCellSelected"];
                    }else
                    {
                        img.image=[UIImage imageNamed:@"editCellUnSelected"];
                    }
                }
            }
        }
    }
    [super layoutSubviews];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end