安哥网络 发表于 2013-11-18 00:22:38

IOS获取网络图片的方法

通常来说,网络的的获取方法,是使用NSURL,NSURLRequest,NSURLConnection,这三个类,但是其实都是使用ASIHttp的第三方类,去获得网络信息。

具体的参考实例如下:

// 判断网络是否通
if ([ currentReachabilityStatus]!=kNotReachable)    {

      NSString *imagePath =@"http://www.weather.com.cn/m/i/weatherpic/29x20/d0.gif";// @"http://img.evolife.cn/2011-07/ad1e1823f6c67c75.jpg";

      NSURL *url = ;
      // 显示进度      MBProgressHUD *loadingView = [[initWithView:self.view]autorelease];      loadingView.labelText = @"正在加载...";      ;      ;      loadingView.taskInProgress = YES;      ;

      // 直接获取,关键点是通过一个block实现,这个方法就不需要通过delegate去实现了。      ASIHTTPRequest *httpRequest = ;
      
            ;
            UIImage *downloadedImage = ];
            progressViewBlue.hidden =YES;
            imageView.image = downloadedImage;      }];

      static longlong downloadedBytes = 0;
                  NSLog(@"size:%lld,total:%lld",size,total);            downloadedBytes += size;            CGFloat progressPercent = (CGFloat)downloadedBytes/total;
            loadingView.progress = progressPercent;

            progressViewBlue.progress = progressPercent;            progressViewYellow.progress = progressPercent;            progressLabel.text = ;
      }];

      ;


    }    else    {      NSLog(@"network not available");    }
这个项目涉及的第三方类:1、Reachability.h,去判断网络是否通。2、ASIHTTPRequest.h 请求。3、MBProgressHUD.h进度显示。4、进度条,彩色的WNProgressView.h。

本文摘自:http://blog.csdn.net/dongdongdongjl/article/details/8496815

页: [1]
查看完整版本: IOS获取网络图片的方法