Home > database >  Change Reorder Control's color in table view cell for iOS 15
Change Reorder Control's color in table view cell for iOS 15

Time:12-04

I am using tableview cell Reorder control in my application and it works well till iOS 14 but not working on iOS 15. In iOS 15 Reorder Control's color is not changed.

Following is code what I used. So how can I change Reorder Control's color in iOS 15.

private var myReorderImage : UIImage? = nil;
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
for subViewA in cell.subviews {
 if (subViewA.classForCoder.description() == "UITableViewCellReorderControl") {
for subViewB in subViewA.subviews {
if (subViewB.isKind(of: UIImageView.classForCoder())) {
let imageView = subViewB as! UIImageView;
if (myReorderImage == nil) {
let myImage = imageView.image;
myReorderImage = myImage?.withRenderingMode(UIImageRenderingMode.alwaysTemplate);
}
 imageView.image = myReorderImage;
imageView.tintColor = UIColor.red;
break;
 }
 }
 break;
}
}
}
                

CodePudding user response:

In iOS 15, I tried to customise Reorder control's icon but failed to do that. So I simply remove UIImageview object from Reorder control. And create my own image view object programmatically and set image to that imageView. And after that add that imageView as addSubview into Reorder control. And it solved my problem.

Follow sharing code so it help to others who face same issue.

private var myReorderImage : UIImage? = nil;
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
for subViewA in cell.subviews {
if (subViewA.classForCoder.description() == "UITableViewCellReorderControl") {
for subViewB in subViewA.subviews {
if (subViewB.isKind(of: UIImageView.classForCoder())) {
subViewB.removeFromSuperview()
let imageView = UIImageView()
 if (self.myReorderImage == nil) {
 let myImage = imageView.image
myReorderImage = myImage?.withRenderingMode(.alwaysTemplate)
}
var frame = imageView.frame
frame.origin.x = 3
frame.origin.y = 14
frame.size = CGSize(width: 21, height: 9)
self.myReorderImage = UIImage(named:"YourImage") // set your image 
imageView.frame = frame
imageView.image = self.myReorderImage
 subViewA.addSubview(imageView) // add imageView to reorder control
break;
 }
 }
break;
}
}
}
  • Related