How to load specific image from assets with Swift [duplicate]

半腔热情 提交于 2019-12-02 19:56:23

You shouldn't load images directly with @2x or @3x, system selects appropriate image automatically, you only need to specify the name, like UIImage(named: "green-square-Retina")

Since swift 3.0 there is more convenient way: #imageLiterals here is text example. And below animated example from here:

You can easily pick image from asset without UIImage(named: "green-square-Retina").

Instead use the image object directly from bundle.
Start typing the image name and you will get suggestions with actual image from bundle. It is advisable practice and less prone to error.

See this Stackoverflow answer for reference.

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