zoukankan      html  css  js  c++  java
  • monotouch中UIWebView显示gif图片

    1、在项目中添加要显示得gif图片文件,并在此文件上右键---->Build Action---->Content,点击选中。(这一步很关键)

    2、在页面中Code,将gif图片加载进UIWebView。

        方法一:

     1     UIWebView LoadDataImg;
     2     //实例化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     //将不透明设置为false
     6     LoadDataImg.Opaque=false;
     7     //获取gif图片得绝对路径,相对路径的话NSData是读取不到数据的。
     8     NSString picPath=new NSString(NSBundle.MainBundle.PathForResource("Img/loadData","gif"));
     9     NSData imgData=NSData.FromFile(picPath);
    10     //加载图片
    11     LoadDataImg.LoadData(imgData,@"image/gif","",new NSUrl(NSBundle.MainBundle.BundlePath));
    12     this.View.AddSubview(LoadDataImg);

        方法二:

     1     UIWebView LoadDataImg;
     2     //实例化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     //将不透明设置为false
     6     LoadDataImg.Opaque=false;
     7     NSUrl localFile=NSUrl.FromFilename("Img/loadData.gif");
     8     NSUrlRequest request=new NSUrlRequest(localFile);
     9     //加载图片
    10     LoadDataImg.LoadRequest(request);
    11     this.View.AddSubview(LoadDataImg);

     3、以上两种编码,分别通过UIWebView得LoadRequest和LoadData方法实现。当然还可以用LoadHtmlString方法实现,但就要求你写html代码了。效果如下:

       

  • 相关阅读:
    【Xamarin破解补丁找不到?】
    【Xamarin挖墙脚系列:Xamarin.Android的API设计准则】
    【给你几个使用Xamarin的理由】
    【Xamarin 跨平台机制原理剖析】
    HttpStatusCode 枚举
    C语音--static变量
    extern "c"用法
    C语言---类型转换
    VS2008资源问题解决方法
    003---hibernate主要接口介绍
  • 原文地址:https://www.cnblogs.com/flowwind/p/3008702.html
Copyright © 2011-2022 走看看