ios - 如何在 UITableViewCell 上突出显示 UIButton
问题描述
单击时如何设置UIButton
突出显示请帮助我,因为我完全陷入了这段代码中
func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) {
let cell = self.leaveDetailTableView.cellForRow(at: indexPath) as? LeaveDetailCell
cell!.cellCardView.backgroundColor = #colorLiteral(red: 0.9568627451, green: 0.8941176471, blue: 0.6549019608, alpha: 1)
}
func tableView(_ tableView: UITableView, didUnhighlightRowAt indexPath: IndexPath) {
let cell = self.leaveDetailTableView.cellForRow(at: indexPath) as? LeaveDetailCell
cell!.cellCardView.backgroundColor = UIColor.white
}
当我选择一个表格视图项目时,我必须用我想选择我自己的颜色的颜色突出显示一个特定的行。
解决方案
如果您想在单击按钮时更改颜色,您可以这样做首先,您应该向按钮添加一个操作
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTapGesture(_:)))
cell.cellCardView.addGestureRecognizer(tapGesture)
完成此操作后,在操作handleTapGesture(_:)
中,您可以像这样更改按钮的颜色
func handleTapGesture(_ sender: UIButton) {
UIView.animate(withDuration: 0.1, animations: {
sender.backgroundColor = #colorLiteral(red: 0.9568627451, green: 0.8941176471, blue: 0.6549019608, alpha: 1)
}) { (_) in
sender.backgroundColor = .white
}
}
推荐阅读
- python - 我应该如何在 Python/Selenium 中缩进一些复杂的代码块?
- three.js - 如何使用 dat.GUI 更改几何颜色?
- java - Java 多维数据集程序在第二个和第三个实例上存在问题
- ios - 使用编程约束 UIKit 使 UIImage 居中(水平或垂直)
- python - 我有一些 JSON 文件是空的,当我尝试遍历它们时出现异常。我该如何进行这项工作?
- java - Android Studio 导航抽屉不处理点击
- angular - 可观察到的角度拦截器返回值
- java - Java:两个并行列格式
- arduino - Arduino如何检测一个键是否被按下
- c# - Azure 聊天机器人中间件的依赖注入?