1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- //
- // GifCollectionViewCell.swift
- // LiveLikeGiphyChallenge
- //
- // Created by Ljupco Nastevski on 30.1.22.
- //
- 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.imageView)
- self.contentView.addSubview(self.titleLabel)
-
-
- self.imageView.translatesAutoresizingMaskIntoConstraints = false
- self.titleLabel.translatesAutoresizingMaskIntoConstraints = false
- NSLayoutConstraint.activate([
-
- self.imageView.topAnchor.constraint(equalTo: self.contentView.topAnchor),
- self.imageView.leadingAnchor.constraint(equalTo: self.contentView.leadingAnchor),
- self.imageView.trailingAnchor.constraint(equalTo: self.contentView.trailingAnchor),
- self.imageView.bottomAnchor.constraint(equalTo: self.contentView.bottomAnchor),
-
- 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)
- }
-
- }
-
- }
|