gpt4 book ai didi

swift - 如何快速按钮突出显示和突出显示颜色为红色

转载 作者:行者123 更新时间:2023-11-30 10:59:08 25 4
gpt4 key购买 nike

如何显示按钮高亮颜色,颜色为红色

extension LeaveDetailVC: cellIndexCall{
func selectBtnIndex(sender: UIButton) {
let buttonPosition:CGPoint = sender.convert(.zero, to:leaveDetailTableView)
var indexPath = leaveDetailTableView.indexPathForRow(at: buttonPosition)
self.indexPath = indexPath!
print("\(String(describing: indexPath?.row))") /* index path of button
self.menuClickIndex = (indexPath?.row)!
}
}

我的按钮覆盖了tableViewCell。我还在单元类中创建了一个按钮委托(delegate),并通过扩展调用 viewController。

我只想突出显示按钮,该按钮位于单元格上方。

最佳答案

  override func tableView(_ tableView: UITableView, shouldHighlightRowAt 
indexPath: IndexPath) -> Bool {
return true
}

override func tableView(_ tableView: UITableView, didHighlightRowAt
indexPath:
IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
cell?.contentView.backgroundColor = UIColor.orange
cell?.backgroundColor = UIColor.orange
}

override func tableView(_ tableView: UITableView, didUnhighlightRowAt
indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
cell?.contentView.backgroundColor = UIColor.black
cell?.backgroundColor = UIColor.black
}

关于swift - 如何快速按钮突出显示和突出显示颜色为红色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53606306/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com