自定义系统编辑模式按钮图片

2017-08-29  本文已影响14人  Lin__Chuan

核心思想: 分析视图结构,找到对应ImgView


for (UIControl *control in self.subviews){
        if ([control isMemberOfClass:NSClassFromString(@"UITableViewCellEditControl")]){
            //找出UITableViewCellEditControl
            for (UIView *view in control.subviews)
            {
                if ([view isKindOfClass: [UIImageView class]]) {
                    //在UITableViewCellEditControl中找到imageView
                    UIImageView *img=(UIImageView *)view;
                    //这样便可以更改按钮的坐标
                    img.frame = CGRectMake(img.frame.origin.x, img.frame.origin.y, img.frame.size.width, img.frame.size.height);
                    //更改按钮图片
                    if (self.selected) {
                        img.image=[UIImage imageNamed:@"purifier_icon_pressed"];
                    }else
                    {
                        img.image=[UIImage imageNamed:@"purifier_icon_normal"];
                    }
                }
            }
        }
    }
上一篇下一篇

猜你喜欢

热点阅读