处理placeHolder 的图片内容类型

来源:互联网 发布:js 封装自定义组件 编辑:程序博客网 时间:2024/06/03 16:03

  对单元格里面放的 图片的 placeholderImage改变一下类型,原理是:

  placeholderImage 后面应该放的是 UIImage  , 为了控制UIImage的内容大小的类型,我们需要有UIImageView, 才能控制它的类型,那么我们就可以利用将UIImageView(UIView) 转化为UIImage的 方法,我们对UIImageView 进行一下内容设置和填充一下图片就好.

  [lmCell.myImageViewsetImageWithURL:[NSURLURLWithString:self.lmImageUrlArray[indexPath.item]]placeholderImage:[selfconvertViewToImage:[selfplaceholderImageView]]];


//下面是这个类的私有方法

-(UIView *)placeholderImageView

{

    UIImageView *imageView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0, _lmCellSize.width,_lmCellSize.height)];

    imageView.backgroundColor =LineGrayColor;

    imageView.image = [UIImageimageNamed:@"img"];

    imageView.contentMode =UIViewContentModeCenter;

    

    return imageView;

}


// UIView UIImage ,,把上面的UIImageView 传过来就好

-(UIImage*)convertViewToImage:(UIView*)view{

    

    CGSize s =view.bounds.size;

    

    // 下面方法,第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示半透明效果,需要传NO,否则传YES。第三个参数就是屏幕密度了

    UIGraphicsBeginImageContextWithOptions(s,NO, [UIScreenmainScreen].scale);

    

    [view.layerrenderInContext:UIGraphicsGetCurrentContext()];

    

    UIImage*image =UIGraphicsGetImageFromCurrentImageContext();

    

    UIGraphicsEndImageContext();

    

    return image;

    

}



0 0
原创粉丝点击