1, imagenamed:
1 UIImage *image = [UIImage imagenamed:@ "1"];
class method of UIImage
The first time you read a picture, put this picture in the cache, the next time you use the name of the picture, read directly from the cache, if the cache does not exist in the name of the image, then the picture is loaded into the cache, and then return the object. If we need to load some one-off images frequently in a short time, it is best not to use this method.
Advantages: Convenient and quick, only the first use of the time is slightly slower, the next use will be a little faster;
Cons: If used only once in the current project, it will waste memory.
2, Imagewithcontentsoffile: and Initwithcontentsoffile:
1 //get the path to a picture resource in the package2NSString *oldimagepath = [[NSBundle mainbundle] Pathforresource:@"Image"OfType:@"PNG"];3 //get pictures by Path4UIImage *image1 = [UIImage Imagewithcontentsoffile:oldimagepath];//class Method5UIImage *image2 = [[UIImage alloc] initwithcontentsoffile:oldimagepath];//Object Methods
Imagewithcontentsoffile:--The class method of UIImage
Intiwithcontentsoffile:--The object method of UIImage
Each time the image is read according to the path, it is loaded and returned directly from the file system without the system cache. This method should be selected if the loaded picture is used only once in the project. When a memory warning is received, the system may release the memory of the UIImage internal storage image and reload it the next time it is needed.
The difference between two types of initialization methods for objects of the UIImage class