美文网首页
SDWebImage加进度条展示图片下载进度

SDWebImage加进度条展示图片下载进度

作者: anyurchao | 来源:发表于2015-11-17 17:55 被阅读3155次

    #import "ViewController.h"

    #import "UIImageView+WebCache.h"

    @interface ViewController ()

    @property (nonatomic,strong) UIImageView *imv;

    @end

    @implementation ViewController

    - (void)viewDidLoad {

    [super viewDidLoad];

    self.imv = [[UIImageView alloc]initWithFrame:self.view.bounds];

    [self.view addSubview:self.imv];

    __block UIProgressView *pv;

    [self.imv sd_setImageWithURL:[NSURL URLWithString:@"http://p1.pichost.me/i/40/1639665.png"] placeholderImage:nil options:SDWebImageCacheMemoryOnly  progress:^(NSInteger receivedSize, NSInteger expectedSize) {

    pv = [[UIProgressView alloc]initWithProgressViewStyle:(UIProgressViewStyleDefault)];

    pv.frame = CGRectMake(0, 0, 400, 20);

    pv.center = self.view.center;

    NSLog(@"%ld,%ld",receivedSize,expectedSize);

    float currentProgress = (float)receivedSize/(float)expectedSize;

    pv.progress = currentProgress;

    [self.imv addSubview:pv];

    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {

    [pv removeFromSuperview];

    }];

    }

    相关文章

      网友评论

          本文标题: SDWebImage加进度条展示图片下载进度

          本文链接:https://www.haomeiwen.com/subject/mdtlhttx.html