我只想为UIButton
设置图像并为其创建一个IBOutlet
。我在它上面有一个加载程序,当加载图像时,加载程序将停止并为该按钮分配一个新图像。调用代码时,占位符图像将保留,并且 url 图像不会加载
[_Image1 sd_setBackgroundImageWithURL:[NSURL URLWithString:[arrayGallery valueForKey:@"link"][0]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"blurred-background"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
[_ImageLoader1 stopAnimating];
[_ImageLoader1 removeFromSuperview];
}];
最佳答案
您正在使用完成 block 从 url 下载图像。所以你需要按照下面的方式做。
[_Image1 sd_setBackgroundImageWithURL:[NSURL URLWithString:[arrayGallery valueForKey:@"link"][0]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"blurred-background"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
[_Image1 setImage:btnImage forState:UIControlStateNormal];//Don't forgot to check for error if error is nil or image is not nil then only set image
[_ImageLoader1 stopAnimating];
[_ImageLoader1 removeFromSuperview];
}];
关于ios - 图像未加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44841173/