简体   繁体   中英

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!

在此处输入图片说明

作为注释,请更改单元格的backgroundColor以匹配单元格的contentView backgroundColor固定,因为annexView与单元格的contentView不相关,并且它将使用单元格背景色作为背景色

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM