【发布时间】:2012-06-29 12:56:40
【问题描述】:
我正在使用 SDWebView 图像,我想显示一个活动指示器作为占位符,同时从远程获取图像。
我在这里How to show an activity indicator in SDWebImage尝试了Malek的回答,但似乎
UIImage *cachedImage = [manager imageWithURL:url];
已弃用。
有没有人使用这个库可以告诉我如何在加载图像时插入活动指示器?
编辑
按照 Michael Frederick 的指示,我最终得到了这段代码,一切正常。
UIActivityIndicatorView *activityIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
activityIndicator.hidesWhenStopped = YES;
activityIndicator.hidden = NO;
[activityIndicator startAnimating];
activityIndicator.center = CGPointMake(self.tipImage.frame.size.width /2, self.tipImage.frame.size.height/2);
[imageView setImageWithURL:[NSURL URLWithString:imageString]
placeholderImage:nil options:SDWebImageProgressiveDownload
success:^(UIImage *image) { [activityIndicator stopAnimating];[activityIndicator removeFromSuperview]; }
failure:^(NSError *error) { [activityIndicator stopAnimating];[activityIndicator removeFromSuperview]; }];
[imageView addSubview:activityIndicator];
【问题讨论】:
-
您是否使用占位符图像?
-
我选择只使用微调器而不是图像,是的,它有效!
-
@Pheel 请不要在问题中添加答案,添加单独的答案(您可以回答自己的问题)。 SO 格式是问题+答案。
标签: objective-c uiactivityindicatorview sdwebimage