How to choose how images are loaded in iOS development

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.