1. Add picture operation with UIImage object when adding picture operation
1.[uiimage imagename:@ "1.png"]
2.[uiimage imagewithcontentsoffile:@ "1.png"]
Note: The difference between imagenamed and Imagewithcontentsoffile
Imagenamed loads the image and caches it, and caches the image in memory, using imagenamed when the image is small and frequently used;
Imagewithcontentsoffile is to display only pictures, but not in memory. So when loading a lot of pictures with imagewithcontentsoffile better, the memory will not become larger.
when adding a picture operation, first modify the image size, as follows :
Note: This is the category extension class for UIImage
①uiimage+scale.h declaration file, passing in a cgsize parameter, that is, the width and height of the picture
<span style= "FONT-SIZE:14PX;" >-(UIImage *) Scaletosize: (cgsize) size;</span>
②.m files, implementing Files
<span style= "FONT-SIZE:14PX;" > //Specify reduced size-(UIImage *) Scaletosize: (cgsize) Size { //Create a bitmap context //and set it as the currently in use context uigraphicsbeginimagecontext (size); Draw a picture that changes size [self drawinrect:cgrectmake (0,0, Size.width, Size.Height)]; Creates a resized image from the current context UIImage * scaledimage = Uigraphicsgetimagefromcurrentimagecontext (); Make the current context out of the stack uigraphicsendimagecontext (); Returns the new resized picture return scaledimage;} </span>
method calls, as follows.
<span style= "FONT-SIZE:14PX;" >uiimage *image = [UIImage imagewithcontentsoffile:@ "1.png"];image = [Image Scaletosize:cgsizemake (30, 30)]; Uiimageview *imgeview = [[Uiimageview alloc] Initwithimage:image];</span>
"Learning iOS: UI series" Modifying the size of a picture operation