gpt4 book ai didi

ios - 如何在 Swift 中更改滑动操作的 UITableviewCell 背景颜色?

转载 作者:行者123 更新时间:2023-11-30 11:27:06 27 4
gpt4 key购买 nike

--------------------- 这是我的代码 ------------------- --

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

let important = importantAction(at: indexPath)
//let delete = deleteAction(at: indexPath)

return UISwipeActionsConfiguration(actions: [important])

}

@available(iOS 11.0, *)
func importantAction(at indexPath: IndexPath) -> UIContextualAction
{


let action = UIContextualAction(style: .normal, title: nil) { (action, view, completion) in


completion(true)
}
action.image = #imageLiteral(resourceName: "checked_wht")
action.backgroundColor = UIColor.green

return action
}

最佳答案

试试这个代码

@available(iOS 11.0, *)
func importantAction(at indexPath: IndexPath) -> UIContextualAction
{
let action = UIContextualAction(style: .normal, title: nil) { (action, view, completion) in
completion(true)
let indexPath = IndexPath(item: indexPath.row, section: 0)
self.tableView.reloadRows(at: [indexPath], with: .top)
}
let cell:UITableViewCell = (tableView.cellForRow(at: IndexPath(row: indexPath.row, section: 0)))!
cell.backgroundColor = UIColor.red
action.backgroundColor = UIColor.green

return action
}

关于ios - 如何在 Swift 中更改滑动操作的 UITableviewCell 背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50623536/

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