首页 > Web开发 > 详细

[MISSAJJ原创]cell内 通过SDWebImage自定义创建动态菊花加载指示器

时间:2015-11-20 06:57:28      阅读:238      评论:0      收藏:0      [点我收藏+]

 

 

之前写在简书APP里了,http://www.jianshu.com/p/d4c09036f366

但是简书APP里很不方便插入代码, 所以还是搬回cnblogs吧

 

 

 

/**
*  cell内 普通图片加载

*/

     

    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:imageToLoad] placeholderImage: [UIImage imageNamed:EMPTY_IMAGE]];

     


 

 

/**
*  cell内 自定义创建图片动态加载指示器

*/

 

__block UIActivityIndicatorView * indicatorPlaceholder;

[cell.imageView sd_setImageWithURL:[NSURL URLWithString:imageToLoad] placeholderImage:nil options:SDWebImageCacheMemoryOnly   progress:^(NSInteger receivedSize, NSInteger expectedSize) {

//创建指示器:必须放在线程内才不会报错

dispatch_async(dispatch_get_main_queue(), ^{

if(!indicatorPlaceholder){

[cell.imageView addSubview:indicatorPlaceholder = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];

indicatorPlaceholder.center = cell.imageView.center;

[indicatorPlaceholder startAnimating];

}

});

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

//如果图片未缓存  渐现效果

if (cacheType == SDImageCacheTypeNone) {

cell.imageView.alpha = 0.5;

[UIView animateWithDuration:1.0  animations:^{

cell.imageView.alpha = 1.0;

}];

}

// 消除指示器

if (indicatorPlaceholder) {

[indicatorPlaceholder removeFromSuperview];

indicatorPlaceholder = nil;

}

}];

 

[MISSAJJ原创]cell内 通过SDWebImage自定义创建动态菊花加载指示器

原文:http://www.cnblogs.com/missajj/p/4979640.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!