// // YMRecomPageCell.swift // MvpGoods // // Created by 小花 on 2019/4/15. // Copyright © 2019 MVP. All rights reserved. // import UIKit class YMRecomPageCell: UITableViewCell { override func awakeFromNib() { super.awakeFromNib() // Initialization code } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) // Configure the view for the selected state } override init(style: UITableViewCellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) configSubViews() } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } class func cellWithTableView(tableView: UITableView) -> UITableViewCell { var cellID: String? cellID = NSStringFromClass(self) var cell = tableView.dequeueReusableCell(withIdentifier: cellID!) if cell == nil { cell = YMRecomPageCell.init(style: .default, reuseIdentifier: cellID) } cell?.selectionStyle = .none return cell ?? UITableViewCell() } var model: YMRecomPageModel? { didSet { // icon.setFadeImage(with: model?.subscribe_img) let imgStr = Int(arc4random() % 100) + 1 var img = UIImage(named: "\(imgStr).jpg") if img == nil { img = UIImage(named: "\(imgStr)") } icon.image = img name.text = model!.subscribe_title! timeLabel.text = model!.pass_time content.text = model!.show_content goodImg.setFadeImage(with: model!.img) let priceT = model!.discount_price price.text = "¥"+(priceT ?? "") } } func configSubViews() { self.contentView.addSubview(icon) self.contentView.addSubview(name) self.contentView.addSubview(timeLabel) self.contentView.addSubview(content) self.contentView.addSubview(goodImg) self.goodImg.addSubview(price) icon.snp.makeConstraints { (make) in make.top.equalTo(self.contentView).offset(15) make.left.equalTo(15) make.width.height.equalTo(40) } goodImg.snp.makeConstraints { (make) in make.left.equalTo(icon.snp.left) make.width.height.equalTo(fitSize(x: 170)) make.bottom.equalTo(self.contentView).offset(-10) } name.snp.makeConstraints { (make) in make.left.equalTo(icon.snp.right).offset(15) make.top.equalTo(icon.snp.top).offset(1) } timeLabel.snp.makeConstraints { (make) in make.left.equalTo(name.snp.left) make.bottom.equalTo(icon.snp.bottom).offset(-1) } content.snp.makeConstraints { (make) in make.left.equalTo(icon.snp.left) make.right.equalTo(-15) make.top.equalTo(icon.snp.bottom).offset(10) make.bottom.equalTo(goodImg.snp.top).offset(-10) } price.snp.makeConstraints { (make) in make.width.equalTo(60) make.height.equalTo(20) make.bottom.right.equalTo(0) } } lazy var icon: UIImageView = { let img = UIImageView() img.backgroundColor = UIColor.gloadGrayColor() return img }() lazy var name: UILabel = { let name = UILabel() name.textColor = UIColor.gloadRedColor() return name }() lazy var timeLabel: UILabel = { let time = UILabel() time.textColor = UIColor.hexadecimalColor(hexadecimal: "#666666") time.font = UIFont.systemFont(ofSize: 14) return time }() lazy var content: UILabel = { let content = UILabel() content.numberOfLines = 0 content.font = UIFont.systemFont(ofSize: 17) content.textColor = UIColor.hexadecimalColor(hexadecimal: "#222222") return content }() lazy var goodImg: UIImageView = { let goodImg = UIImageView() goodImg.backgroundColor = UIColor.gloadGrayColor() return goodImg }() lazy var price: UILabel = { let price = UILabel() price.backgroundColor = UIColor.gloadRedColor() price.font = UIFont.systemFont(ofSize: 14) price.textColor = UIColor.white price.textAlignment = .center return price }() }