UIImage is a more difficult way to display pictures, UIImage can display pictures from a file or ImageData. If you can graphically operate, it is recommended to use the ImageView Control to display the picture, after all, is a graphical visual operation.
When creating a picture from ImageData, be sure to pay attention to the size and size of the image, because this is in memory, if the picture is too large or too many pictures, it is easy to cause memory leaks, if you choose a picture from a file, you can manually select whether the picture is in memory.
The UIImage supported image types are: TIFF,TIF,JPG,JPEG,GIF,PNG,BMP,BMPF,ICO,CUR,XBM. UIImage commonly used to load pictures from a file in the following ways: 1. + (UIImage *) imagenamed: (NSString *)
nameFeatures: The most convenient, the most efficient way to load pictures. However, the use of this way to load the picture, after the first load, the picture will be cache in memory, so there is a certain risk of memory leaks, must not be loaded too large or disposable folder in too many pictures, and immediately after the use of memory release; Parameter name, the file name, if the picture is stored in the project path in the sub-physical folder, you only need to specify the file name, the system will automatically find the sub-directory of the picture. 2. + Imagewithcontentsoffile:or-(ID) Initwithcontentsoffile: (NSString *) path features: Use more code, but will not cache the picture in memory, but need to provide pictures of For the specific path and picture name sample code, set the background picture for the current Viewcontroller (Uiviewcontroller):
// Set the current Viewcontroller (uiviewcontroller) Background image // First method UIImage *bgimage = [UIImage imagenamed: @ "bg.png"= [Uicolor colorwithpatternimage:bgimage]; // The second method of NSString *path = [[NSBundle mainbundle] Pathforresource:@ "bg.png" oftype:nil Indirectory:@ ""*bgimage2 == [Uicolor colorwithpatternimage:bgimage2];
Transferred from: http://www.cnblogs.com/xunziji/archive/2012/09/25/2701928.html
Do not quite understand how the author so hate reprint, anyway I was turned, keep the good check later.