// // KMAdvertisementShowScrollCell_iOS.swift // KMAdvertisement // // Created by lizhe on 2022/11/29. // import UIKit import Kingfisher class KMAdvertisementShowScrollCell_iOS: UICollectionViewCell { @IBOutlet weak var cancelButton: UIButton! @IBOutlet weak var titleLabel: UILabel! @IBOutlet weak var actionButton: UIButton! @IBOutlet weak var imageView: UIImageView! var model: KMAdvertisementModel.Section.Content! { didSet { self.reloadData() } } override func awakeFromNib() { super.awakeFromNib() // Initialization code // self.backgroundColor = UIColor.init(red: CGFloat(arc4random()%255)/255.0, green: CGFloat(arc4random()%255)/255.0, blue: CGFloat(arc4random()%255)/255.0, alpha: 1) let bundle = Bundle(for: self.classForCoder.self) let path = bundle.path(forResource: "KMAdvertisement", ofType: "bundle") ?? "" let sdkBundle = Bundle(path: path) let filePath = sdkBundle?.path(forResource: "ad_cancel_button00@2x", ofType: "png") let image = UIImage.init(contentsOfFile: filePath!) self.cancelButton.setTitle("", for: UIControl.State.normal) self.cancelButton.setImage(image, for: UIControl.State.normal) self.cancelButton.isHidden = true self.actionButton.setTitle("", for: UIControl.State.normal) } func reloadData() { if model?.title?.language != nil { self.titleLabel.text = KMAdvertisementModelTransition.transitionLanguage(langeuage: model?.title?.language) } self.titleLabel.font = UIFont.init(name: model?.title?.font?.name ?? "AppleSystemUIFont", size: CGFloat(model?.title?.font?.size ?? 13)) self.actionButton.clipsToBounds = true self.actionButton.layer.cornerRadius = model.button?.background?.layer?.cornerRadius ?? 15 self.actionButton.layer.borderWidth = model.button?.background?.layer?.borderWidth ?? 0 self.actionButton.titleLabel?.font = UIFont.init(name: model?.button?.font?.name ?? "AppleSystemUIFont", size: CGFloat(model?.button?.font?.size ?? 13)) if model?.button?.language != nil { self.actionButton.setTitle(KMAdvertisementModelTransition.transitionLanguage(langeuage: model?.button?.language), for: UIControl.State.normal) } self.imageView.clipsToBounds = true self.imageView.layer.cornerRadius = model.imageURL?.background?.layer?.cornerRadius ?? 8 self.imageView.layer.borderWidth = model.imageURL?.background?.layer?.borderWidth ?? 0 self.updateColor(highlight: false) } func updateColor(highlight: Bool) { if model.title?.color != nil { self.titleLabel.textColor = KMAdvertisementModelTransition.transitionColor(color: (model.title?.color)!, highlight: highlight) } if model.button?.background?.color != nil { self.actionButton.layer.borderColor = KMAdvertisementModelTransition.transitionColor(color: (model.button?.background?.color)!, highlight: highlight).cgColor } if model.button?.color != nil { self.actionButton.tintColor = KMAdvertisementModelTransition.transitionColor(color: (model.button?.color)!, highlight: highlight) } if model.imageURL != nil { self.imageView?.kf.setImage(with: URL(string: KMAdvertisementModelTransition.transitionImagePath(image: model.imageURL!, highlight: highlight))) } } }