LNAdBannerImageCell.swift 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // LNAdBannerImageCell.swift
  3. // Lanu
  4. //
  5. // Created by Codex on 2026/4/8.
  6. //
  7. import Foundation
  8. import UIKit
  9. import SnapKit
  10. final class LNAdBannerImageCell: UICollectionViewCell {
  11. private let imageView = UIImageView()
  12. private var curItem: LNBannerInfoVO?
  13. override init(frame: CGRect) {
  14. super.init(frame: frame)
  15. setupViews()
  16. }
  17. required init?(coder: NSCoder) {
  18. fatalError("init(coder:) has not been implemented")
  19. }
  20. override func prepareForReuse() {
  21. super.prepareForReuse()
  22. curItem = nil
  23. imageView.image = nil
  24. }
  25. func update(_ item: LNBannerInfoVO) {
  26. curItem = item
  27. imageView.sd_setImage(with: URL(string: item.img))
  28. }
  29. }
  30. private extension LNAdBannerImageCell {
  31. func setupViews() {
  32. contentView.layer.masksToBounds = true
  33. contentView.layer.cornerRadius = 16
  34. imageView.layer.masksToBounds = true
  35. imageView.layer.cornerRadius = 16
  36. imageView.contentMode = .scaleAspectFill
  37. contentView.addSubview(imageView)
  38. imageView.snp.makeConstraints { make in
  39. make.edges.equalToSuperview()
  40. }
  41. }
  42. }