我使用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!
答案 0 :(得分:3)
作为评论,更改单元格的baseclass::somemethod
以匹配单元格的内容backgroundColor
修复它,因为accessoryView与单元格的contentView无关,它将使用单元格背景颜色作为背景颜色