// // GifCollectionViewCell.swift import UIKit class GifCollectionViewCell: UICollectionViewCell { static let reuseIdentifier = NSStringFromClass(GifCollectionViewCell.self) private lazy var imageView: LLAnimatableImageView = { let imageView = LLAnimatableImageView() imageView.contentMode = .center imageView.clipsToBounds = true return imageView }() private lazy var titleLabel: UILabel = { let lbl = UILabel() lbl.numberOfLines = 0 return lbl }() var gif: GifObject? { didSet{ self.didSetGif() } } override init(frame: CGRect) { super.init(frame: frame) self.setupSelf() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } private func setupSelf() { self.contentView.addSubview(self.titleLabel) // TODO: Add an Image to the UICollectionViewCell // Use `self.imageView` variable to add an image to the cell. // Please make the image height and width conform to the cell's bounds self.titleLabel.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ self.titleLabel.bottomAnchor.constraint(equalTo: self.contentView.bottomAnchor), self.titleLabel.leadingAnchor.constraint(equalTo: self.contentView.leadingAnchor), self.titleLabel.trailingAnchor.constraint(equalTo: self.contentView.trailingAnchor), self.titleLabel.heightAnchor.constraint(lessThanOrEqualTo: self.contentView.heightAnchor, multiplier: 0.5) ]) } private func didSetGif() { if let gif = gif { self.titleLabel.text = gif.title self.imageView.loadGifFromUrl(urlString: gif.images.fixedWidth.url) } } }