首页 > 解决方案 > Disclosure Indicator 背景后面的 Swift UITableViewCell 视图在明亮模式下没有变化

问题描述

我在更改 UITableViewCell 的背景颜色时遇到问题。

我将单元格的背景颜色设置为 UIColor.systemGray6 但是披露指示器周围的颜色仍然是白色。但在暗模式下,它可以正常工作,如下图所示:

这是我包含披露指标的单元格代码:

class SettingsDiscolsureCell: UITableViewCell {
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
        
        self.contentView.backgroundColor = UIColor.systemGray6
        self.textLabel?.font = UIFont(name: "AvenirNext", size: UIFont.labelFontSize)
        
        self.accessoryType = .disclosureIndicator
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

我试过self.accessoryView?.backgroundColor = .systemGray6但注意到改变了

为什么会发生这种情况,我应该怎么做才能改变整个背景颜色?

标签: iosswiftuitableviewuikit

解决方案


而不是为 UITableViewCell 的 contentView 分配颜色,使用这个

self.backgroundColor = UIColor.systemGray6

您的单元格背景颜色将显示在附件类型下方


推荐阅读