作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在尝试在 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
}
注意:我使用了 50*50 points apple.png 图片和 50 个 tableview
row height
关于ios - 如何在 UITableViewRowAction 中添加图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44771778/
我是一名优秀的程序员,十分优秀!