IOS UIImage Two types of initialization differences

Source: Internet
Author: User

UIImage can be initialized in one of the following two ways:

1//The first initialization mode: "Note that when using this initialization if the PNG format can not give the suffix name, according to the resolution of the screen to match the picture" 2 3 UIImage *image = [UIImage imagenamed:@ "V_red_heart_ Selected "];

  

1    ///second initialization mode: "The full name of the picture must be stitched, otherwise the path of the image is empty" 2    nsstring = [[NSBundle mainbundle] pathforresource:@ "[ Email protected] "Oftype:nil"; 3     UIImage *image = [[UIImage alloc] initwithcontentsoffile:filepath];

  

The difference between the two ways: the first type of initialization:

Use imagenamed: First read the time, first put this picture in the cache, the next time you use the same name image to read directly from the cache; Advantages: quick and easy, only the first use of the time is slightly slower, the next use will be a little bit faster ; disadvantage: If used only once in the current project, it will waste memory. "This is only released when the program is closed."

The second method of initialization:

When using Initwithcontentsoffile to initialize a picture, each time it is read according to the path, does not occupy memory, if the picture is used only once in the current project, you should choose this method

IOS UIImage Two types of initialization differences

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.