停止重复 UIImage 背景图案图像 - Swift [英] Stop repeating UIImage background pattern image - Swift

查看:44
本文介绍了停止重复 UIImage 背景图案图像 - Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using swipe to delete in UITableView. In swipe I need to add image. When I add image it repeats. How to stop repeating

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

问题

我需要什么

推荐答案

问题,正如你可能已经猜到的那样:

The problem, as you might have guessed, is here:

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

您正在使用 (patternImage:) 初始值设定项创建 UIColor.这意味着图像将被重复(看到图案"这个词了吗?).

You are creating a UIColor using the (patternImage:) initializer. This means that the image will be repeated (See the word "pattern"?).

来自文档:

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

You can use pattern colors to set the fill or stroke color just as you would a solid color. During drawing, the image in the pattern color is tiled as necessary to cover the given area.

要解决此问题,您可以通过编程调整图像大小,使其适合按钮的框架.请参阅调整 UIImage 大小的最简单方法?

To solve this, you can resize your image so that it fits the frame of the button programmatically. See The simplest way to resize an UIImage?

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

Alternatively, use MGSwipeTableViewCell, it allows you to put images on swipe buttons.

这篇关于停止重复 UIImage 背景图案图像 - Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆