skip to Main Content

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;
}
}
}
                

2

Answers


  1. Chosen as BEST ANSWER

    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;
    }
    }
    }
    

  2. This is the objective code solution created based on the previous answer with some minor changes:

    // Change cell reorder control tint color to white color (while on editing mode)
    for (UIView *subViewA in self.subviews)
    {
        // Check if cell subview corresponds to cell rerorder control
        if ([NSStringFromClass (subViewA.class) isEqualToString: @"UITableViewCellReorderControl"])
        {
            for (UIView *subViewB in subViewA.subviews)
            {
                // Check if cell reorder control subview corresponds to image view
                if ([subViewB isKindOfClass: [UIImageView class]])
                {
                    // Set reorderImage variable with current image view's image and rendering mode "always"
                    self.reorderImage = [[(UIImageView *) subViewB image] imageWithRenderingMode: UIImageRenderingModeAlwaysTemplate];
                    
                    // Set new image view with current image view frame, reorder image variable, and white tint color
                    UIImageView *imageView = [[UIImageView alloc] init];
                    imageView.frame = subViewB.frame;
                    imageView.image = self.reorderImage;
                    imageView.tintColor = [UIColor whiteColor];
                    
                    // Remove old image view from cell reorder control view hierarchy
                    [subViewB removeFromSuperview];
                    
                    // Add new image view to cell reorder control view hierarchy
                    [subViewA addSubview: imageView];
    
                    break;
                }
            }
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search