首先获取图片 url 并检查图片 url 长度是否大于零null
。并确保图像 url 是否正常工作。点击url
打开Browser
并检查您是否获得正确的图像。
SDWebImage
库正在更新按钮图像,但这并没有发生在Main Thread
. 这可能是不更新的backgroundImage
原因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];
}
停止loader
动画并设置UIButton
背景图像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];
});
}];
}