Godlike Godlike - 1 year ago 203
iOS Question

Swift - How to change the color of an accessoryType (disclosureIndicator)?

I have question about the

accessoryType
of cells. I am using a cell with an
disclosureIndicator
as
accessoryType
and I want to change it's color but I can't.
Does anyone know if this is a bug or if Apple forces me to use the grey color?
Actually I can change the colors of other
accessoryType
.

My code looks like this:

let cell = tableView.dequeueReusableCell(withIdentifier: "identifier", for: indexPath) as! customCell
cell.tintColor = UIColor.red
cell.accessoryType = .disclosureIndicator


And my arrow is still grey. But if I use a checkmark
accessoryType
it becomes red.

Is there any way to fix this or do I have to use a colored image?

Answer Source

You can do something like this

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
}

Sample Arrow Images

enter image description here enter image description here

Output

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download