[英]Show UIButton image as round with SDWebImage
我的代碼曾經在切換到SDWebImage之前可以工作。 但是現在它不起作用了。 我的意思是,圖像顯示為正方形而不是圓形。 這是我的代碼
- (void)makeImageViewRound:(UIButton *)imageButton
{
imageButton.imageView.layer.cornerRadius = imageButton.imageView.bounds.size.width/2;
imageButton.imageView.clipsToBounds = YES;
imageButton.imageView.layer.borderWidth=0.5;
imageButton.imageView.layer.masksToBounds = YES;
imageButton.imageView.layer.borderColor=[[UIColor blackColor] CGColor];
}
…
self makeImageViewRound: self.catImageButton];
…
[self.catImageButton sd_setImageWithURL:catUrl forState:UIControlStateNormal];
我寧願不必進入並更改SDWebImage本身來解決此問題。
您是否嘗試過從SDWebImage的api的另一種方法的完成塊中舍入視圖?
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock;
如果仍然無法解決問題,您可以始終先將下載的圖像四舍五入。 檢查這個問題:
應用新圖像后,使用完成塊和GCD更改主線程中的圖像視圖。
- (void)makeImageViewRound:(UIButton *)imageButton {
imageButton.imageView.layer.cornerRadius = imageButton.imageView.bounds.size.width/2;
imageButton.imageView.clipsToBounds = YES;
imageButton.imageView.layer.borderWidth=0.5;
imageButton.imageView.layer.masksToBounds = YES;
imageButton.imageView.layer.borderColor=[[UIColor blackColor] CGColor];
}
....
[catImageButton sd_setImageWithURL:catUrl forState:UIControlStateNormal completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if (error) {
return;
}
__weak typeof (self) weak_self = self;
dispatch_async(dispatch_get_main_queue(), ^{
[weak_self makeImageViewRound: weak_self.catImageButton];
});
}];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.