I'm looking for a way to change the default delete icon colour from red to blue when a table is 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.
I'm looking for a way to change the default delete icon colour from red to blue when a table is 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.
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:
How to know UITableViewCellEditControl
?
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
?
and