5

I'm looking for a way to change the default delete icon colour from red to blue when a table is in edit mode.

Table view in edit mode

The red icons on the left are what I am talking about and are default when setting a table view to edit mode.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Eli Stone
  • 1,515
  • 4
  • 33
  • 57
  • Maybe that can help you? http://stackoverflow.com/questions/27163171/change-color-of-png-in-buttons-ios – Guy Daher Feb 09 '16 at 21:54
  • Or this: http://stackoverflow.com/questions/24142591/swipe-to-expose-more-flag-archive-buttons-like-in-mail-app-on-ios-8/24540538#24540538 – paulvs Feb 10 '16 at 02:16
  • None of these talk about the default icons that are shown when when a table view is set to editing. – Eli Stone Feb 10 '16 at 11:50
  • Maybe this article will help you: http://vinsol.com/blog/2015/01/06/custom-edit-control-for-uitableviewcell/ – no81no Mar 17 '16 at 18:03

1 Answers1

0

Better to change the red color image _system.remove to your own blue image.

func swizzle() {

    guard let cls = NSClassFromString("UITableViewCellEditControl") else { return }
    let originalSelector = NSSelectorFromString("_updateImageView")
    let swizzledSelector = #selector(UIView._updateImageViewHijack)
    let originMethod = class_getInstanceMethod(cls, originalSelector)
    let swizzleMethod = class_getInstanceMethod(UIView.self, swizzledSelector)
    if let swizzledMethod = swizzleMethod, let originalMethod = originMethod{
        method_exchangeImplementations(originalMethod, swizzledMethod)
    }
    
    
    let originalS = NSSelectorFromString("layoutSubviews")
    let swizzledS = #selector(UIView.layoutSubviewsHijack)
    let originM = class_getInstanceMethod(cls, originalS)
    let swizzleM = class_getInstanceMethod(UIView.self, swizzledS)
    if let swizzledM = swizzleM, let originalM = originM{
        method_exchangeImplementations(originalM, swizzledM)
    }
}
        



extension UIView{
    @objc func _updateImageViewHijack(){
        _updateImageViewHijack()
        for v in subviews{
            if let img = v as? UIImageView{
                img.image = UIImage(named: "one.png")
            }
        }
        
    }
    
    
    @objc func layoutSubviewsHijack(){
        layoutSubviewsHijack()
        for v in subviews{
            if let img = v as? UIImageView{
                img.image = UIImage(named: "one.png")
            }
        }
    }
}

swizzle() should be call once only.

And the result:

3333


How to know UITableViewCellEditControl ?

99


How to know methods of UITableViewCellEditControl ?

via runtime

                var count: UInt32 = 0
                guard let methodArr = class_copyMethodList(NSClassFromString("UITableViewCellEditControl"), &count) else { return }
                
                let cnt = Int(count)
                for i in 0..<cnt{
                    let method = methodArr[i]
                    let name = method_getName(method)
                    if let type = method_getTypeEncoding(method){
                        print(name, String(utf8String: type) ?? " _ | _ ")
                    }
                }

How to know the size of image _system.remove ?

99889

and

6666

dengApro
  • 3,848
  • 2
  • 27
  • 41