ios - 为什么 editActionsForRowAt 返回很多图像而不是一张图像?

标签 ios swift tableview nsindexpath

enter image description here 我想向表格 View 单元格添加滑动操作,但是当我添加图像而不是背景颜色时,它会返回很多图像。

这是我正在尝试的:

func tableView(_ tableView: UITableView, editActionsForRowAt: IndexPath) -> [UITableViewRowAction]? {
    let delete = UITableViewRowAction(style: .default, title: "") { action, index in
        print("more button tapped")
    }
    delete.backgroundColor = UIColor(patternImage: circularIcon(with: .red, size: CGSize(width: 50, height: 50), icon: #imageLiteral(resourceName: "trash-alt"))!)

    let edit = UITableViewRowAction(style: .default, title: "") { action, index in
        print("favorite button tapped")
    }
    edit.backgroundColor = UIColor(patternImage: circularIcon(with: UIColor.appColor(.green)!, size: CGSize(width: 50, height: 50), icon: #imageLiteral(resourceName: "pen-1"))!)

    return [delete, edit]
}

最佳答案

因为它是从图像创建一个图案,所以没有正确地进行宽度/高度计算,所以它只是从中创建一个图案。我打赌你可以从这里得到答案: Using buttons/images in tableView:editActionsForRowAt:

关于ios - 为什么 editActionsForRowAt 返回很多图像而不是一张图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58011479/

相关文章:

ios - 如何在 swift UI Test 下检查应用程序状态

objective-c - UIWebView 显示 HTML 太大

ios - AVPlayer 缓冲后停止播放视频

swift - PFQuery 中的逻辑运算符错误

ios - 如何在 tableView swift 中快速进行数组追加和排序

iphone - 如何在 iPhone 上生成柏林噪声

ios - 使用单例获取 "unrecognized selector sent to class"

swift - 我可以使用 ARKit 一次跟踪 4 张以上的图像吗?

java - 如何在javafx中的TableView中禁用右键单击所选行?

tableview - 请解释如何使用 CheckBoxTableCell