sguruapp@gmail.com
facebook vk instagram Телеграм youtube

Изменение цвета ячейки (cell) при нажатии в TableView (Change background color in cell when pressed) - Swift 5


override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier:"Cell", for: indexPath)

// Убираем выделение ячейки цветом при нажатии
cell.selectionStyle = .none
}


override func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)

// Цвет, при нажатии
cell!.contentView.backgroundColor = UIColor(red : 233.0/255.0, green : 242.0/255.0, blue: 250.0/255.0, alpha: 1.0)
}

override func tableView(_ tableView: UITableView, didUnhighlightRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)

// Цвет, при отжатии
cell!.contentView.backgroundColor = .white
}

Возврат к списку

обучись профессии будущего

Хочешь стать успешным разработчиком
приложений? Тогда добро пожаловать к нам.

обучись профессии будущего