Is there a recommended image size for UIContextualAction icons?

谁都会走 提交于 2019-12-06 10:02:11
matt

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))
    }

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).

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

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])
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!