1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- //
- // 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)
- }
-
- }
-
- }
|