Mike Mertsock
Mike Mertsock

Reputation: 12015

Is there a recommended image size for UIContextualAction icons?

New in iOS 11, UIContextualAction provides a convenient way to implement swipe actions on UITableView cells, with a title and/or image icon.

I haven't found any mention in the Human Interface Guidelines of the image used by UIContextualAction. Does any information exist that defines a standard size or other design guidance for this icon image?

I tried to figure this out by testing a few image sizes to see if iOS would scale it to a consistent size, but it seems to just display whatever you give it with no scaling or cropping, so that didn't provide any clues.

Upvotes: 4

Views: 6907

Answers (3)

matt
matt

Reputation: 535222

I use 30 by 30. You can render your image down to that size in code easily enough.

    let d = UIContextualAction(style: .destructive, title: nil) {
        action, view, completion in
        // ... whatever ...
        completion(true)
    }
    d.image = UIGraphicsImageRenderer(size: CGSize(width: 30, height: 30)).image { _ in
        UIImage(named: "trash")?.draw(in: CGRect(x: 0, y: 0, width: 30, height: 30))
    }

Upvotes: 22

Niraj Paul
Niraj Paul

Reputation: 1538

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.

Type of image that is support

enter image description here

func tableView(_ tableView: UITableView,
                   trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
    {
        // Write action code for the trash
        let TrashAction = UIContextualAction(style: .normal, title:  "Delete", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
            print("Update action ...")
                    success(true)
        })
       TrashAction.backgroundColor = .white
       TrashAction.image =  UIImage(imagename: “dustbin”)           
       return UISwipeActionsConfiguration(actions: [TrashAction])
    }

Upvotes: 1

DrMickeyLauer
DrMickeyLauer

Reputation: 4674

There is no recommendation here, since a standard size does not make much sense given the variety of UITableViewCell sizes – it's depending on the concrete app and device it's running on. I recommend you resize the icon on runtime – don't forget to leave a bit of room to breath (vertical margin = 8px or so).

Upvotes: 2

Related Questions