Search code examples
iosobjective-cxcodesdwebimage

Set image from SDWebImage to background of button


I use SDWebImage in my project but I was wondering if there is a way to set the image to the background of a button?


Solution

  • SDWebImageManager *manager = [SDWebImageManager sharedManager];
    [manager downloadImageWithURL:imageURL
                      options:0
                     progress:^(NSInteger receivedSize, NSInteger expectedSize) {
                         // progression tracking code
                     }
                     completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                         if (image) {
                             // do something with image
                            [button setBackgroundImage:image forState:UIControlStateNormal];
    
    
                         }
                     }];