0

My code used to work before switching to SDWebImage. But now it is not working. I mean, the image is presented as a square as opposed to a circle. Here is my code

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

I would rather not have to go in and change SDWebImage itself to solve this.

Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199
  • What about changing `- (void)makeImageViewRound:(UIButton *)imageButton` to `- (void)makeImageViewRound:(SDWebImage *)imageButton` – pkatsourakis Aug 26 '14 at 16:51
  • Have you tried making the button round instead of the image? Might be a simple solution. – LeffelMania Aug 26 '14 at 16:53
  • @PanoKatsourakis the only thing left to try is your idea. But you seem to misread my method. The methods takes a UIButton and then manipulates the Image**View** of the UIButton. But you are saying to use an image. Do you mind showing it in an example? Would I be making the call in a completion block? I don't get it. – Katedral Pillon Aug 26 '14 at 19:01

2 Answers2

0

Did you tried to round your view in completion block of another method from SDWebImage's api?

- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock;


If that still won't work you can always round firstly your downloaded image. Check this question:

Rounded Corners on UIImage

Community
  • 1
  • 1
ArturOlszak
  • 2,653
  • 2
  • 21
  • 20
  • The problem I have had with completion blocks in SDWebImage is that they tend to cause things to happen more slowly by a matter of seconds. I don't know why, but they don't work fast enough for me on UITAbleViews – Katedral Pillon Aug 26 '14 at 19:02
0

Use completion block and GCD to change image view in main thread after applying the new image.

- (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];
    });
}];
primax79
  • 428
  • 2
  • 14
ethanhuang13
  • 483
  • 5
  • 13