The first method: Imagenamed: (often repeated use of the icon with this, the picture is not big)
Why are there two ways to do the same thing? The advantage of imagenamed is that you can cache images that have already been loaded.
This method will first look for the image in the system cache according to the specified name, and return if found. If a picture is not found in the cache, the method loads the picture data from the specified file, caches it, and then returns the result. For the same image, the system will only cache it to memory once, which is very advantageous for the reuse of images. For example: You need to reload the same icon in a tableview, then load the image with Imagenamed, the system will cache the icon to memory, in the table every time the image is used, only the picture pointer to the same piece of memory. In this case, loading the image using imagenamed becomes very effective.
The second method: Imagewithcontentsoffile (with very few places, such as a new feature interface, released after use, no re-use)
The method simply loads the picture, does not cache the picture, and the image is loaded into the program by the system in the form of data. This is useful when you don't need to reuse the image, or if you need to store the image in a database, or you want to download a large image over the network.
How to choose how images are loaded in iOS development