4

我发现它UITableViewCell's accessoryView在 iOS 13 上具有灰色背景色,但在系统设置中运行良好。

我已经尝试设置UITableView背景颜色和色调颜色,但它们都不起作用。

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

   cell!.accessoryType = .disclosureIndicator        

Xcode 调试层次结构视图中的层次结构:

在此处输入图像描述

原因从系统 imageView 看是这样的:

在此处输入图像描述

4

2 回答 2

6

我也注意到了这个问题。即使您为附件视图分配了一个显示指示器,该视图仍然返回 nil。我一直在等待 Apple 解决这个问题,但他们似乎不会很快解决这个问题。因此,我在 UITableViewCell 上创建了一个扩展来处理 iOS13 和以前的 iOS 版本。

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

我希望这有帮助。下面是两个模拟器的截图,一个运行 iOS12.2,另一个运行 iOS13。该应用程序名为七十二。

iOS12.2 与 iOS13 截图

于 2019-10-03T03:26:50.973 回答
1

我的cell也有同样的问题,我的解决方法是继承UITableViewCell,然后在accessoryView中使用自定义图片。</p>

self.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrow"]];
于 2019-09-26T01:34:45.700 回答