我想在我的代码中使用SDWebImage来使用我的图像缓存,但我想使用圆形图像。
使用此代码,我可以使用圆形图像并完美运行:
NSString *imageURL = [noticia objectForKey:@"imagem"];
UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(20, 5, 90, 70)];
imgView.backgroundColor=[UIColor clearColor];
[imgView.layer setCornerRadius:30];
[imgView.layer setMasksToBounds:YES];
[imgView setImageWithURL:[NSURL URLWithString:imageURL]];
cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
[cell.contentView addSubview:imgView];
但我需要使用SDWebImage和缓存,所以我有这个代码:
[cell.imageView setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:[UIImage imageNamed:@"placeholder.png"] ];
我想知道如何合并代码以使用SDWebImage和圆形图像。
我尝试了这段代码,但没有奏效:
UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(20, 5, 90, 70)];
imgView.backgroundColor=[UIColor clearColor];
[imgView.layer setCornerRadius:30];
[imgView.layer setMasksToBounds:YES];
[imgView setImageWithURL:[NSURL URLWithString:imageURL]];
[cell.imageView setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:[UIImage imageNamed:@"placeholder.png"] ];
[cell.contentView addSubview:imgView];
答案 0 :(得分:2)
试试这个: 替换您的代码
UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(20, 5, 90, 70)];
imgView.backgroundColor=[UIColor clearColor];
[imgView.layer setCornerRadius:30];
[imgView.layer setMasksToBounds:YES];
[imgView setImageWithURL:[NSURL URLWithString:imageURL]];
[cell.imageView setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:[UIImage imageNamed:@"placeholder.png"] ];
使用以下代码并导入“QuartzCore / QuartzCore.h”框架
cell.imageView.backgroundColor=[UIColor clearColor];
[cell.imageView.layer setCornerRadius:30];
[cell.imageView.layer setMasksToBounds:YES];
[cell.imageView setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage: [UIImage imageNamed:@"placeholder.png"] ];