How to add image in UITableViewRowAction?

前端 未结 6 993
囚心锁ツ
囚心锁ツ 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条回答
  •  隐瞒了意图╮
    2020-11-30 06:56

    Finally in iOS 11, SWIFT 4 We can add add image in UITableView's swipe action with help of UISwipeActionsConfiguration

    @available(iOS 11.0, *)
        func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    
                let action =  UIContextualAction(style: .normal, title: "Files", handler: { (action,view,completionHandler ) in
                    //do stuff
                    completionHandler(true)
                })
            action.image = UIImage(named: "apple.png")
            action.backgroundColor = .red
            let configuration = UISwipeActionsConfiguration(actions: [action])
    
            return configuration
        }
    

    WWDC video at 28.34

    Apple Doc

    Note: I have used 50*50 points apple.png image with 50 tableview row height

提交回复
热议问题