Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCell's accessoryView has a gray background color on iOS 13

Tags:

ios

I find that UITableViewCell's accessoryView has a gray background color on iOS 13, but it works fine in system settings.

I have tried set the UITableView background color and tint color none of them worked.

var cell = tableView.dequeueReusableCell(withIdentifier: "myInfo")
if (cell==nil) {
   cell = UITableViewCell.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: "myInfo")
}

   cell!.accessoryType = .disclosureIndicator        

The hierarchy in Xcode debug hierarchy view:

enter image description here

The reason looks like from the system imageView:

enter image description here

like image 532
magic_9527 Avatar asked Mar 03 '23 09:03

magic_9527


2 Answers

I have also noticed this issue. Even if you assign a disclosure indicator to the accessoryView, the view still returns nil. I have been waiting for Apple to fix this but it doesn't seem like they will anytime soon. Therefore, I created an extension on UITableViewCell to handle iOS13 and previous iOS builds.

extension UITableViewCell {
    func createCustomCellDisclosureIndicator(chevronColor: UIColor) {
        //MARK: Custom Accessory View
        //Chevron img
        if #available(iOS 13.0, *) {
            let chevronConfig = UIImage.SymbolConfiguration(pointSize: 14, weight: .medium)
            guard let chevronImg = UIImage(systemName: "chevron.right", withConfiguration: chevronConfig)?.withTintColor(chevronColor, renderingMode: .alwaysTemplate) else { return }
            let chevron = UIImageView(image: chevronImg)
            chevron.tintColor = chevronColor

            //chevron view
            let accessoryViewHeight = self.frame.height
            let customDisclosureIndicator = UIView(frame: CGRect(x: 0, y: 0, width: 15, height: accessoryViewHeight))
            customDisclosureIndicator.addSubview(chevron)

            //chevron constraints
            chevron.translatesAutoresizingMaskIntoConstraints = false
            chevron.trailingAnchor.constraint(equalTo: customDisclosureIndicator.trailingAnchor,constant: 0).isActive = true
            chevron.centerYAnchor.constraint(equalTo: customDisclosureIndicator.centerYAnchor).isActive = true

            //Assign the custom accessory view to the cell
            customDisclosureIndicator.backgroundColor = .clear
            self.accessoryView = customDisclosureIndicator
        } else {
            self.accessoryType = .disclosureIndicator
            self.accessoryView?.tintColor = chevronColor
        }
    }
}

I hope this helps. Below is a screenshot of two simulators with one running iOS12.2 and the other iOS13. The app is called seventytwo.

iOS12.2 vs. iOS13 Screenshot

like image 69
Josh R Avatar answered May 28 '23 12:05

Josh R


I have the same problem in my cell, and my workaround is to inherit UITableViewCell, then use the custom image in the accessoryView。

self.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrow"]];
like image 22
acumen Avatar answered May 28 '23 14:05

acumen