First get the image url and check the image url length is greater than zero / not null
. And make sure the image url is working correctly or not. Hit the url
on Browser
and check are you getting proper image.
SDWebImage
library is updating the button image, But that's not happening on Main Thread
. This might be the reason for not updating backgroundImage
of the UIButton
.
- (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
forState:(UIControlState)state
placeholderImage:(nullable UIImage *)placeholder
options:(SDWebImageOptions)options
completed:(nullable SDExternalCompletionBlock)completedBlock {
if (!url) {
[self.imageURLStorage removeObjectForKey:@(state)];
return;
}
NSString *imageURL = [arrayGallery valueForKey:@"link"][0];
self.imageURLStorage[@(state)] = url;
__weak typeof(self)weakSelf = self;
[self sd_internalSetImageWithURL:url
placeholderImage:placeholder
options:options
operationKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]
setImageBlock:^(UIImage *image, NSData *imageData) {
[weakSelf setBackgroundImage:image forState:state];
}
progress:nil
completed:completedBlock];
}
Stop loader
animation and set UIButton
background image on main thread
.
NSString *imageURL = [arrayGallery valueForKey:@"link"][0];
if (imageURL.length > 0) {
[_Image1 sd_setBackgroundImageWithURL:[NSURL URLWithString:imageURL] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"blurred-background"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
dispatch_async(dispatch_get_main_queue(), ^{
[_ImageLoader1 stopAnimating];
[_ImageLoader1 removeFromSuperview];
[_Image1 setBackgroundImage:image forState:UIControlStateNormal];
});
}];
}