'Use Nuke to load image into UICollectionViewListCell
UICollectionViewListCell is configured like so:
var configuration = cell.defaultContentConfiguration()
configuration.text = "Foo"
configuration.image = UIImage(named: "foo")
configuration.imageProperties.maximumSize = CGSize(width: 40, height: 40)
cell.contentConfiguration = configuration
How can I use Nuke to load the image from a URL? With UITableViewCell, we can do:
Nuke.loadImage(with: url, into: cell.imageView)
But UICollectionViewListCell does not have an imageView.
Solution 1:[1]
I did with kingfisher:
var content = cell.defaultContentConfiguration()
let image = UIImageView()
image.image = UIImage(named:"EmptyProfile.png")
if let url = URL(string: user.avatarURL) {
image.load(url: url)
}
content.image = image.image
cell.contentConfiguration = content
--
extension UIImageView {
func load(url: URL) {
self.kf.setImage(with: url)
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jeremy Caney |
