【问题标题】:rounded image using SDWebImage使用 SDWebImage 的圆形图像
【发布时间】:2013-11-21 23:58:08
【问题描述】:

我想在我的代码中使用 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];

【问题讨论】:

    标签: uitableview sdwebimage


    【解决方案1】:

    试试这个: 替换你的代码

      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"] ];
    

    【讨论】:

      猜你喜欢
      • 2014-10-20
      • 1970-01-01
      • 1970-01-01
      • 2012-10-13
      • 1970-01-01
      • 1970-01-01
      • 2021-08-28
      • 1970-01-01
      • 2016-05-07
      相关资源
      最近更新 更多