0

i am trying to add image in the UIContextualAction , see the code below:-

func tableView(_ tableView: UITableView,
               trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
{
   // Write action code for the Flag
    let FlagAction = UIContextualAction(style: .normal, title:  "View", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
        print("Update action ...")
        success(true)
    })
    FlagAction.image =  UIImage(named: "flag")
    return UISwipeActionsConfiguration(actions: [FlagAction])
}

enter image description here

The image , i am using

enter image description here

Niraj Paul
  • 1,498
  • 14
  • 22

3 Answers3

0

we can take size 30 by 30 , is the standard size , we can take more than 30 pixel , depending on the size of the screen.

Here is the image that is support

enter image description here

Niraj Paul
  • 1,498
  • 14
  • 22
0

The UIContextualAction only accepts template image, which use different transparent degree to define the image's shape and color.

Jonny
  • 1,969
  • 18
  • 25
0

hi it is worked fine for me ,

That image size will auto adjust according to pixel of the image.

  private func searchBarCode(forRowAt indexPath: IndexPath) -> UIContextualAction {
    
    let context = UIContextualAction(style: .destructive, title: "") { (action, swipeButtonView, completion) in
        completion(true)
    }
    context.backgroundColor = UIColor.white
    context.image = UIImage(named: "document")
    
    return context
    }

Click here to see table view edit image

Sahil Omer
  • 163
  • 9