首页 > 解决方案 > sd_setImage 显示蓝色图像

问题描述

我正在使用 SDWebImage 设置单元格按钮图像:

cell.categoryButton.sd_setImage(with: URL(string:cell.image), for: .normal, placeholderImage: UIImage(named: "image"))

但我得到的是这样的蓝色图像:我不知道为什么 在此处输入图像描述

标签: swiftuibuttonsdwebimage

解决方案


您需要使用该sd_setBackgroundImage属性,因为您正在设置按钮 ( UIButton) 的背景图像,而不是将图像设置为UIImageView.

cell.categoryButton.sd_setBackgroundImage(with: URL(string:cell.image), for: .normal, completed: nil)

推荐阅读