【问题标题】:Stop repeating UIImage background pattern image - Swift停止重复 UIImage 背景图案图像 - Swift
【发布时间】:2017-12-08 07:41:42
【问题描述】:

我在 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]
}

问题

我需要什么

【问题讨论】:

    标签: uitableview swift3 uiimage


    【解决方案1】:

    你可能已经猜到了,问题就在这里:

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

    您正在使用(patternImage:) 初始化程序创建UIColor。这意味着图像将被重复(看到“模式”这个词吗?)。

    来自docs

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-18
      • 1970-01-01
      • 1970-01-01
      • 2015-09-30
      • 2013-03-09
      • 2013-02-03
      • 1970-01-01
      相关资源
      最近更新 更多