KMAdvertisementShowScrollCell_iOS.swift 4.0 KB

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