处理placeHolder 的图片内容类型

  对单元格里面放的 图片的 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;

    

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值