因网络图片加载用的是SDWebImage
所以下面以sd
加载图片为例
//普通的加载网络图片方式(已不能满足需求,需要改进)
[self sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:placeholderImage]];
//设置圆角图片的加载方法
[self sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:placeholderImage] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if (!error) {
//图片需要手动缓存处理成圆角的图片(该方法用的是YYImage里面的处理方式)
UIImage *radiusImage = [image imageByRoundCornerRadius:image.size.width * (radius / self.size.width) corners:corners borderWidth:borderWidth borderColor:borderColor borderLineJoin:borderLineJoin];
self.image = radiusImage;
//将带圆角的图片缓存下来
[[SDImageCache sharedImageCache] storeImage:radiusImage forKey:cacheUrlStr completion:nil];
//清除原有非圆角图片缓存
[[SDImageCache sharedImageCache] removeImageForKey:url.absoluteString withCompletion:nil];
}
}];
到此为止就已经结束了
初光夫