Is there a recommended image size for UIContextualAction icons?

隐身守侯 提交于 2020-01-13 13:11:38

问题


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.


回答1:


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



回答2:


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




回答3:


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


来源:https://stackoverflow.com/questions/47502901/is-there-a-recommended-image-size-for-uicontextualaction-icons

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