【问题标题】:swift swipe tableview cell set image with trailingSwipeActionsConfigurationForRowAt AND editActionsForRowAt使用 trailingSwipeActionsConfigurationForRowAt 和 editActionsForRowAt 快速滑动 tableview 单元集图像
【发布时间】:2018-02-14 11:46:58
【问题描述】:

滑动表格视图单元格,然后显示一些删除和编辑的选项。我想设置完整的图像。我看过很多演示代码,但都是文本和背景图像,我需要用整个图像创建这里是我的 ios 10 和 ios 11 代码,但我无法成功

使用 editActionsForRowAt 问题是图像重复多次

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?
    {


            let ArchiveAction = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "          ") { (action , indexPath ) -> Void in



                 tableView.setEditing(false, animated: false)
            }

            let shareAction = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "          ") { (action , indexPath) -> Void in

                tableView.setEditing(false, animated: false)
            }

            ArchiveAction.backgroundColor = UIColor(patternImage: UIImage(named: "archiver.png")!)
            shareAction.backgroundColor = UIColor(patternImage: UIImage(named: "bloquear.png")!)


            return [ArchiveAction,shareAction]

    }

使用 trailingSwipeActionsConfigurationForRowAt 问题是图像无法正确显示。显示白色图像

@available(iOS 11.0, *)
    func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

        let action =  UIContextualAction(style: .normal, title: "sdfsdf", handler: { (action,view,completionHandler ) in
            //do stuff
            completionHandler(true)
        })
       // action.image = UIImage(named: "archiver.png")

        action.backgroundColor = .black
        let confrigation = UISwipeActionsConfiguration(actions: [action])
         confrigation.performsFirstActionWithFullSwipe = true // default is false
        return confrigation
    }

请给我任何解决方案

【问题讨论】:

    标签: uitableview swipe


    【解决方案1】:

    我在使用.jpg时也遇到了白色矩形而不是图像的问题。使用 .png 对我有用。

    由于您已经在使用 .png,您是否尝试加载不带 .png 扩展名的图像名称? ("archiver" 而不是 "archiver.png")

    因为init?(named name: String)的参数说明说:

    ...对于 PNG 图像,您可以省略文件扩展名。对于所有其他文件格式,请始终包含文件扩展名。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-05
      • 1970-01-01
      • 1970-01-01
      • 2014-10-31
      • 2016-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多