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

来源:互联网 发布:.cx域名投资 编辑:程序博客网 时间:2024/06/05 00:40
#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];    }];}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}

0 0
原创粉丝点击