How to add image in UITableViewRowAction?

前端 未结 6 991
囚心锁ツ
囚心锁ツ 2020-11-30 05:58

I\'m trying to add image in UITableView Swipe style. I tried with Emoji text & its working fine

func tableView(_ tableView: UITableView, edi         


        
6条回答
  •  萌比男神i
    2020-11-30 06:42

    I found one way of doing this in SWIFT 3 -

     func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
            //let cell = tableView.cellForRow(at: indexPath)
            //print(cell?.frame.size.height ?? 0.0)//hence we need this height of image in points. make sure your contentview of image is smaller
            let deleteAction = UITableViewRowAction(style: .normal, title:"       ") { (rowAction, indexPath) in
                print("delete clicked")
            }
            deleteAction.backgroundColor = UIColor(patternImage:UIImage(named: "delete")!)
            return [deleteAction]
        }
    

    We need to make sure our image dimension is matching with cell row height Here is my image which i used

提交回复
热议问题