我对细胞的accessoryType有疑问。我正在使用一个带有disclosureIndicator作为accessoryType的单元格,我想改变它的颜色,但我不能。有人知道这是一个bug还是苹果强迫我使用灰色的颜色吗?实际上,我可以改变其他accessoryType的颜色。
我的代码如下所示:
let cell = tableView.dequeueReusableCell(withIdentifier: "identifier", for: indexPath) as! customCell
cell.tintColor = UIColor.red
cell.accessoryType = .disclosureIndicator我的箭仍然是灰色的。但是如果我使用一个复选标记accessoryType,它就会变成红色。
有什么办法可以解决这个问题吗?还是我必须使用彩色图像?
发布于 2017-07-05 13:29:20
你可以做这样的事
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
    cell.tintColor = UIColor.white
    let image = UIImage(named: "Arrow.png")
    let checkmark  = UIImageView(frame:CGRect(x:0, y:0, width:(image?.size.width)!, height:(image?.size.height)!));
    checkmark.image = image
    cell.accessoryView = checkmark
    let object = objects[indexPath.row] as! NSDate
    cell.textLabel!.text = object.description
    return cell
}样本箭图像


输出

发布于 2020-03-24 01:46:22
使用SF符号
let image = UIImage(systemName: "chevron.right")
let accessory  = UIImageView(frame:CGRect(x:0, y:0, width:(image?.size.width)!, height:(image?.size.height)!))
accessory.image = image
// set the color here
accessory.tintColor = UIColor.white
cell.accessoryView = accessory发布于 2018-12-15 01:58:41
更新为SWIFT4.2,附图片
    cell.accessoryType = .disclosureIndicator
    cell.tintColor = .black
    let image = UIImage(named:"disclosureArrow")?.withRenderingMode(.alwaysTemplate)
    if let width = image?.size.width, let height = image?.size.height {
        let disclosureImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: width, height: height))
        disclosureImageView.image = image
        cell.accessoryView = disclosureImageView
    }您可以使用的图像:



它可能是什么样子:

https://stackoverflow.com/questions/44927146
复制相似问题