Uiwebview display GIF image in monotouch

Source: Internet
Author: User

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:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.