Modify reorder control icon in table view editing mode
<p>I'd like to use a custom color for the hamburger icon that appears in table view editing mode, preferably even use a custom image. I've found this Swift code snippet in an older thread which was in Objective-C originally (to be found here: <a href="https://stackoverflow.com/questions/8603359/change-default-icon-for-moving-cells-in-uitableview">Change default icon for moving cells in UITableView</a>):</p>

<pre><code>override func setEditing(editing: Bool, animated: Bool) {
    super.setEditing(editing, animated: animated)

    if editing {
        for view in subviews as [UIView] {
            if view.dynamicType.description().rangeOfString("Reorder") != nil {
                for subview in view.subviews as [UIImageView] {
                    if subview.isKindOfClass(UIImageView) {
                        subview.image = UIImage(named: "yourimage.png")
                    }
                }
            }
        }
    }
}
</code></pre>

<p>To fit my <code>TableViewController</code>, I've changed the line beginning the loop to:
<code>for view in tableView.subviews as [UIView] {</code> which seems to work, but the view with the description "Reorder" will not be found. Has this been changed since?</p>

<p>I would have asked in the old thread but due to reputation I am not allowed yet.</p>

<p>Any insight very welcome!</p>

<p><strong>EDIT</strong>: I could change the images by changing the above code to:</p>

<pre><code>override func setEditing(editing: Bool, animated: Bool) {
    super.setEditing(editing, animated: animated)

    if editing {
      for cell in tableView.visibleCells {
        for view in cell.subviews {
          if view.dynamicType.description().rangeOfString("Reorder") != nil {
            for subview in view.subviews as! [UIImageView] {
              if subview.isKindOfClass(UIImageView) {
                subview.image = UIImage(named: "yourimage.png")
                //subview.frame = CGRect(x: 0, y: 0, width: 20, height: 20)
              }
            }
          }
        }
      }
   }
}
</code></pre>

<p>There is a bug, however, when scrolling down not all the icons will be changed. some cells will still have the original icon. I guess that has got something to do with the cells being reused. Is there any solution to this?</p>

<p><strong>EDIT 2</strong>: I fixed the above issue by making sure the same image replacement logic is being executed in the <code>cellForRowAtIndexPath</code> method. Also, I'm checking if the image is already changed, as the image would have weird offsets if there had been an image before.</p>

<pre><code>override func setEditing(editing: Bool, animated: Bool) {
  super.setEditing(editing, animated: animated)

  if editing {
    for cell in tableView.visibleCells {
      setEditingAccessoryView(forCell: cell)
    }
  }
}

func setEditingAccessoryView(forCell cell: UITableViewCell) {
  for view in cell.subviews {
    if view.dynamicType.description().rangeOfString("Reorder") != nil {
      for subview in view.subviews as! [UIImageView] {
        if subview.isKindOfClass(UIImageView) {
          if subview.image != UIImage(named: "yourImage.png") {
            subview.image = UIImage(named: "yourImage.png")
            //subview.frame = CGRect(x: 20, y: 20, width: 20, height: 20)
          }
        }
      }
    }
  }
}
</code></pre>

<p>In cellForRowAtIndexPath:</p>

<pre><code>if editing {
  setEditingAccessoryView(forCell: cell)
}
</code></pre>