Change default icon for moving cells in UITableView

前端 未结 11 1545
面向向阳花
面向向阳花 2020-11-28 21:46

I need to change default icon for moving cells in UITableView.

This one:

\"enter

11条回答
  •  孤城傲影
    2020-11-28 22:24

    This is a really hacky solution, and may not work long term, but may give you a starting point. The re-order control is a UITableViewCellReorderControl, but that's a private class, so you can't access it directly. However, you could just look through the hierarchy of subviews and find its imageView.

    You can do this by subclassing UITableViewCell and overriding its setEditing:animated: method as follows:

    - (void) setEditing:(BOOL)editing animated:(BOOL)animated
    {
        [super setEditing: editing animated: YES];
    
        if (editing) {
    
            for (UIView * view in self.subviews) {
                if ([NSStringFromClass([view class]) rangeOfString: @"Reorder"].location != NSNotFound) {
                    for (UIView * subview in view.subviews) {
                        if ([subview isKindOfClass: [UIImageView class]]) {
                            ((UIImageView *)subview).image = [UIImage imageNamed: @"yourimage.png"];
                        }
                    }
                }
            }
        }   
    }
    

    Or in Swift

    override func setEditing(_ editing: Bool, animated: Bool) {
        super.setEditing(editing, animated: animated)
    
        if editing {
            for view in subviews where view.description.contains("Reorder") {
                for case let subview as UIImageView in view.subviews {
                    subview.image = UIImage(named: "yourimage.png")
                }
            }
        }
    }
    

    Be warned though... this may not be a long term solution, as Apple could change the view hierarchy at any time.

提交回复
热议问题