UITableViewCellAccessoryType Изменить цвет галочки
Я пытаюсь выяснить, как программно (а не в раскадровке) установить цвет для UITableViewCellAccessoryType.Checkmark.
Я чувствую себя глупо, спрашиваю, как сделать что-то простое, но это не удалось найти в яблочных документах. Любая помощь будет большой. Спасибо.
Я установил тип аксессуара следующим образом: (отлично работает)
cell.accessoryType = .Checkmark
EDIT: Если вы хотите изменить изображение, используемое для галочки, это сработало для меня. Но ответ POB - это то, что я использовал, чтобы просто изменить цвет.
let checkImage = UIImage(named: "checkmark.png")
let checkmark = UIImageView(image: checkImage)
cell.accessoryView = checkmark
Ответы
Ответ 1
Следующий код должен работать:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
//Change cell tint color
cell.tintColor = UIColor.redColor()
//Set UITableViewCellAccessoryType.Checkmark here if necessary
cell.accessoryType = .Checkmark
/* ... */
return cell
}
Ответ 2
Вот код для Swift 3.0
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.tintColor = UIColor.red
cell.accessoryType = .checkmark
return cell
}
Ответ 3
Вы также можете сделать это глобально (для всех ячеек табличного представления) следующим образом:
UITableViewCell.appearance().tintColor = .green
Хороший маленький трюк :)