ios - 在编辑模式下将图像添加到 UITableViewCell 未正确对齐

标签 ios swift image uitableview edit

我正在使用下面的代码来尝试获得这样的外观:

enter image description here

但它看起来像:

enter image description here

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
    let deleteRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "Delete") { action, indexPath in

    }
    deleteRowAction.backgroundColor = UIColor.red
    deleteRowAction.backgroundColor = UIColor(patternImage: UIImage(named: "DeleteIcon.png")!)
    return [deleteRowAction]
    }

我做错了什么?

最佳答案

只需更改:

deleteRowAction.backgroundColor = UIColor(patternImage: UIImage(named: "DeleteIcon.png")!)

至:

deleteRowAction.image = UIImage(named: "DeleteIcon.png")

它应该可以工作。

关于ios - 在编辑模式下将图像添加到 UITableViewCell 未正确对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46478078/

相关文章:

ios - 使用 Firebase 检索多查询

swift 3 (macOS) : keyDown(with event: NSEvent) doesn't get called

java - 在 JLabel 上显示加密图像

android + 通用图像加载器 : show custom marker with image in google map

ios - 当 NSData 输入始终相同时,NSXMLParser 有时只会给出错误代码 4

ios - 显示后将元素添加到 MonoTouch 对话框 RootElement 时出现奇怪的 block

iphone - Xcode 4.2 中烦人的代码签名错误/警告

swift - 快速的大中央调度(GCD)

ios - swift 3 : Hide UITableView if Empty

android:在类中加载图像