之前写在简书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