停止重复UIImage背景图案图像 - Swift

时间:2017-12-08 07:41:42

标签: uitableview swift3 uiimage

我在UITableView中使用滑动删除。在滑动我需要添加图像。当我添加图像时,它重复。如何停止重复

 func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
        let deleteButton = UITableViewRowAction(style: .default, title: "Delete") { (action, indexPath) in
            self.tableView.dataSource?.tableView!(self.tableView, commit: .delete, forRowAt: indexPath)
            return
        }

        deleteButton.backgroundColor = UIColor(patternImage: #imageLiteral(resourceName: "favourite_delete"))
        deleteButton.title = ""
            return [deleteButton]
}

问题

enter image description here

我需要什么

enter image description here

1 个答案:

答案 0 :(得分:1)

正如您可能已经猜到的那样,问题在于:

deleteButton.backgroundColor = UIColor(patternImage: #imageLiteral(resourceName: "favourite_delete"))

您正在使用UIColor初始值设定项创建(patternImage:)。这意味着图像将被重复(参见“模式”一词?)。

来自docs

  

您可以使用图案颜色设置填充或描边颜色,就像使用纯色一样。 在绘制过程中,图案颜色中的图像会根据需要平铺以覆盖给定区域。

要解决此问题,您可以调整图像大小,使其以编程方式适合按钮的框架。见The simplest way to resize an UIImage?

或者,使用MGSwipeTableViewCell,它允许您将图像放在滑动按钮上。

相关问题