GiphyCollectionViewCell.swift 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //
  2. // GiphyCollectionViewCell.swift
  3. // LiveLikeGiphyChallenge
  4. //
  5. // Created by Arbnor Tefiki on 6.2.22.
  6. //
  7. import UIKit
  8. class GiphyCollectionViewCell: UICollectionViewCell {
  9. fileprivate let imageView: CachedImageView = {
  10. let imageView = CachedImageView()
  11. imageView.contentMode = .scaleAspectFill
  12. imageView.clipsToBounds = true
  13. imageView.translatesAutoresizingMaskIntoConstraints = false
  14. return imageView
  15. }()
  16. override init(frame: CGRect) {
  17. super.init(frame: frame)
  18. commonInit()
  19. }
  20. required init?(coder: NSCoder) {
  21. super.init(coder: coder)
  22. commonInit()
  23. }
  24. private func commonInit() {
  25. contentView.addSubview(imageView)
  26. setupConstraints()
  27. }
  28. func setupConstraints() {
  29. NSLayoutConstraint.activate([
  30. imageView.topAnchor.constraint(equalTo: contentView.topAnchor),
  31. imageView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
  32. imageView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
  33. imageView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
  34. ])
  35. }
  36. func setupCell(url: String) {
  37. self.imageView.loadAsyncImage(url: url, placeholder: UIImage(named: "default_image"))
  38. }
  39. }