KMAdvertisementShowScrollCell_iOS.swift 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // KMAdvertisementShowScrollCell_iOS.swift
  3. // KMAdvertisement
  4. //
  5. // Created by lizhe on 2022/11/29.
  6. //
  7. import UIKit
  8. import Kingfisher
  9. class KMAdvertisementShowScrollCell_iOS: UICollectionViewCell {
  10. @IBOutlet weak var cancelButton: UIButton!
  11. @IBOutlet weak var titleLabel: UILabel!
  12. @IBOutlet weak var actionButton: UIButton!
  13. @IBOutlet weak var imageView: UIImageView!
  14. var model: KMAdvertisementModel.Section.Content! {
  15. didSet {
  16. self.reloadData()
  17. }
  18. }
  19. override func awakeFromNib() {
  20. super.awakeFromNib()
  21. // Initialization code
  22. // self.backgroundColor = UIColor.init(red: CGFloat(arc4random()%255)/255.0, green: CGFloat(arc4random()%255)/255.0, blue: CGFloat(arc4random()%255)/255.0, alpha: 1)
  23. let bundle = Bundle(for: self.classForCoder.self)
  24. let path = bundle.path(forResource: "KMAdvertisement", ofType: "bundle") ?? ""
  25. let sdkBundle = Bundle(path: path)
  26. let filePath = sdkBundle?.path(forResource: "ad_cancel_button00@2x", ofType: "png")
  27. let image = UIImage.init(contentsOfFile: filePath!)
  28. self.cancelButton.setTitle("", for: UIControl.State.normal)
  29. self.cancelButton.setImage(image, for: UIControl.State.normal)
  30. self.cancelButton.isHidden = true
  31. self.actionButton.setTitle("", for: UIControl.State.normal)
  32. }
  33. func reloadData() {
  34. if model?.title?.language != nil {
  35. self.titleLabel.text = KMAdvertisementModelTransition.transitionLanguage(langeuage: model?.title?.language)
  36. }
  37. self.titleLabel.font = UIFont.init(name: model?.title?.font?.name ?? "AppleSystemUIFont", size: CGFloat(model?.title?.font?.size ?? 13))
  38. self.actionButton.clipsToBounds = true
  39. self.actionButton.layer.cornerRadius = model.button?.background?.layer?.cornerRadius ?? 15
  40. self.actionButton.layer.borderWidth = model.button?.background?.layer?.borderWidth ?? 0
  41. self.actionButton.titleLabel?.font = UIFont.init(name: model?.button?.font?.name ?? "AppleSystemUIFont", size: CGFloat(model?.button?.font?.size ?? 13))
  42. if model?.button?.language != nil {
  43. self.actionButton.setTitle(KMAdvertisementModelTransition.transitionLanguage(langeuage: model?.button?.language), for: UIControl.State.normal)
  44. }
  45. self.imageView.clipsToBounds = true
  46. self.imageView.layer.cornerRadius = model.imageURL?.background?.layer?.cornerRadius ?? 8
  47. self.imageView.layer.borderWidth = model.imageURL?.background?.layer?.borderWidth ?? 0
  48. self.updateColor(highlight: false)
  49. }
  50. func updateColor(highlight: Bool) {
  51. if model.title?.color != nil {
  52. self.titleLabel.textColor = KMAdvertisementModelTransition.transitionColor(color: (model.title?.color)!, highlight: highlight)
  53. }
  54. if model.button?.background?.color != nil {
  55. self.actionButton.layer.borderColor = KMAdvertisementModelTransition.transitionColor(color: (model.button?.background?.color)!, highlight: highlight).cgColor
  56. }
  57. if model.button?.color != nil {
  58. self.actionButton.tintColor = KMAdvertisementModelTransition.transitionColor(color: (model.button?.color)!, highlight: highlight)
  59. }
  60. if model.imageURL != nil {
  61. self.imageView?.kf.setImage(with: URL(string: KMAdvertisementModelTransition.transitionImagePath(image: model.imageURL!, highlight: highlight)))
  62. }
  63. }
  64. }