对单元格里面放的 图片的 placeholderImage改变一下类型,原理是:
placeholderImage 后面应该放的是 UIImage , 为了控制UIImage的内容大小的类型,我们需要有UIImageView, 才能控制它的类型,那么我们就可以利用将UIImageView(UIView) 转化为UIImage的 方法,我们对UIImageView 进行一下内容设置和填充一下图片就好.
[lmCell.myImageView setImageWithURL:[NSURL URLWithString:self.lmImageUrlArray[indexPath.item]] placeholderImage:[self convertViewToImage:[self placeholderImageView]]];
//下面是这个类的私有方法
-(UIView *)placeholderImageView
{
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, _lmCellSize.width, _lmCellSize.height)];
imageView.backgroundColor = LineGrayColor;
imageView.image = [UIImage imageNamed:@"img"];
imageView.contentMode = UIViewContentModeCenter;
return imageView;
}
// UIView 转 UIImage ,,把上面的UIImageView 传过来就好
-(UIImage*)convertViewToImage:(UIView*)view{
CGSize s =view.bounds.size;
// 下面方法,第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示半透明效果,需要传NO,否则传YES。第三个参数就是屏幕密度了
UIGraphicsBeginImageContextWithOptions(s, NO, [UIScreen mainScreen].scale);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage*image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}