ios - 图像未加载图像

标签 ios objective-c input-button-image

我只想为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/

相关文章:

ios - UINavigationController pushviewcontroller 内存管理

iphone - 如何让 NSURLConnection 委托(delegate)方法触发?

css - 输入按钮,使用 CSS 的单个图像翻转

html - 使用 CSS 和图像设计提交按钮的样式

ios - 比 days/7 更准确地计算自纪元以来的周数

ios - 更新表格 View 内容框架原点

objective-c - 将 NSMutableArray 或 NSMutableDictionary 传递给一个方法——你可以添加它吗?

ios - 我是否需要为尚未获得苹果批准的现有项目更新 Xcode 9.0 和 IOS 11?

ios - NSInputStream 停止运行,有时会抛出 EXC_BAD_ACCESS