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