如何更改UItableview cell accesoryType的背景​​颜色?

时间:2018-04-05 02:52:00

标签: ios swift uitableview

我使用UITableviewCell的附件类型checkmark属性来区分所选单元格与其他单元格,但我倾向于在它下面得到这个奇怪的背景视图?

        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

1 个答案:

答案 0 :(得分:3)

作为评论,更改单元格的baseclass::somemethod以匹配单元格的内容backgroundColor修复它,因为accessoryView与单元格的contentView无关,它将使用单元格背景颜色作为背景颜色