1. Add the GIF image file to be displayed in the project, right-click the file ----> build action ----> content, and click Select. (This step is critical)
2. Code in the page and load the GIF image into uiwebview.
Method 1:
1 uiwebview loaddataimg; 2 // instantiate uiwebview 3 loaddataimg = new uiwebview (new system. drawing. rectanglef (this. view. frame. width/2-78, this. view. frame. height/2-48,156, 95); 4 loaddataimg. backgroundcolor = uicolor. clear; 5 // Set opacity to false 6 loaddataimg. opaque = false; 7 // obtain the absolute path of the GIF image. nsdata cannot be read from the relative path. 8 nsstring picpath = new nsstring (nsbundle. mainbundle. pathforresource ("img/loaddata", "GIF"); 9 nsdata imgdata = nsdata. fromfile (picpath); 10 // load image 11 loaddataimg. loaddata (imgdata, @ "image/GIF", "", new nsurl (nsbundle. mainbundle. bundlepath); 12 this. view. addsubview (loaddataimg );
Method 2:
1 uiwebview loaddataimg; 2 // instantiate uiwebview 3 loaddataimg = new uiwebview (new system. drawing. rectanglef (this. view. frame. width/2-78, this. view. frame. height/2-48,156, 95); 4 loaddataimg. backgroundcolor = uicolor. clear; 5 // Set opacity to false 6 loaddataimg. opaque = false; 7 nsurl localfile = nsurl. fromfilename ("img/loaddata.gif"); 8 nsurlrequest request = new nsurlrequest (localfile); 9 // load image 10 loaddataimg. loadrequest (request); 11 this. view. addsubview (loaddataimg );
3. The above two types of codes are implemented through the loadrequest and loaddata methods obtained by uiwebview respectively. Of course, you can also use the loadhtmlstring method, but it requires you to write HTML code. The effect is as follows: