SriTeja Chilakamarri
SriTeja Chilakamarri

Reputation: 2703

How to change the background color of the UItableview cell accesoryType?

I am using an UITableviewCell's Accessory type checkmark property to distinguish the selected cell with the other cells, but I tend to get this weird background view below it ?

        cell!.selectionStyle = .none
        cell?.backgroundColor = UIColor.clear
        cell?.tintColor = UIColor(hexString: "#866bff")
        cell?.contentView.backgroundColor = UIColor(hexString: "#F8F9FA")
        cell!.textLabel!.font = UIFont(name: "OpenSans", size: optionsSize)
        cell!.textLabel!.textColor = UIColor(hexString: "#484D57")  //optionsTextColor ?? tint ?? cell!.textLabel!.textColor
        cell!.textLabel!.textAlignment = optionsTextAlignment ?? cell!.textLabel!.textAlignment
        cell!.textLabel!.text = "\(options[indexPath.row])"
        //cell!.accessoryType = indexPath.row == selectedIndex ? .checkmark : .none

        if(indexPath.row == selectedIndex){

            cell?.accessoryType = .checkmark
        }else{
            cell?.accessoryType = .none
        }

        cell?.textLabel?.textColor = indexPath.row == selectedIndex ? UIColor(hexString: "#866bff") : tint


        return cell!

enter image description here

Upvotes: 0

Views: 73

Answers (1)

Tj3n
Tj3n

Reputation: 9943

As the comment, change the cell's backgroundColor to match cell's contentView backgroundColor fixed it since accessoryView is not related to cell's contentView and it will use cell background color as it's background color

Upvotes: 3

Related Questions