gpt4 book ai didi

ios - 如何在 UITableViewRowAction 中添加图像?

转载 作者:IT王子 更新时间:2023-10-29 05:39:30 25 4
gpt4 key购买 nike

我正在尝试在 UITableView 滑动样式中添加图像。我尝试使用表情符号文本,效果很好

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let editAction = UITableViewRowAction(style: .normal, title: "🖋") { (rowAction, indexPath) in
print("edit clicked")
}

return [editAction]
}

但我需要图像而不是表情符号,同时我尝试了

editAction.backgroundColor = UIColor.init(patternImage: UIImage(named: "edit")!)

但它得到了重复的图像,我使用了多种格式的图像,如 20*20、25*25、50*50,但仍然重复。

如何添加图片?

最佳答案

最后在 iOS 11 中,SWIFT 4 我们可以在 UISwipeActionsConfiguration 的帮助下在 UITableView 的滑动操作中添加添加图像

@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

let action = UIContextualAction(style: .normal, title: "Files", handler: { (action,view,completionHandler ) in
//do stuff
completionHandler(true)
})
action.image = UIImage(named: "apple.png")
action.backgroundColor = .red
let configuration = UISwipeActionsConfiguration(actions: [action])

return configuration
}

WWDC video at 28.34

Apple Doc

注意:我使用了 50*50 points apple.png 图片和 50 个 tableview row height

关于ios - 如何在 UITableViewRowAction 中添加图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44771778/

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