优惠券swift版马甲包

YMRecomPageCell.swift 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //
  2. // YMRecomPageCell.swift
  3. // MvpGoods
  4. //
  5. // Created by 小花 on 2019/4/15.
  6. // Copyright © 2019 MVP. All rights reserved.
  7. //
  8. import UIKit
  9. class YMRecomPageCell: UITableViewCell {
  10. override func awakeFromNib() {
  11. super.awakeFromNib()
  12. // Initialization code
  13. }
  14. override func setSelected(_ selected: Bool, animated: Bool) {
  15. super.setSelected(selected, animated: animated)
  16. // Configure the view for the selected state
  17. }
  18. override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
  19. super.init(style: style, reuseIdentifier: reuseIdentifier)
  20. configSubViews()
  21. }
  22. required init?(coder aDecoder: NSCoder) {
  23. fatalError("init(coder:) has not been implemented")
  24. }
  25. class func cellWithTableView(tableView: UITableView) -> UITableViewCell {
  26. var cellID: String?
  27. cellID = NSStringFromClass(self)
  28. var cell = tableView.dequeueReusableCell(withIdentifier: cellID!)
  29. if cell == nil {
  30. cell = YMRecomPageCell.init(style: .default, reuseIdentifier: cellID)
  31. }
  32. cell?.selectionStyle = .none
  33. return cell ?? UITableViewCell()
  34. }
  35. var model: YMRecomPageModel? {
  36. didSet {
  37. // icon.setFadeImage(with: model?.subscribe_img)
  38. let imgStr = Int(arc4random() % 100) + 1
  39. var img = UIImage(named: "\(imgStr).jpg")
  40. if img == nil {
  41. img = UIImage(named: "\(imgStr)")
  42. }
  43. icon.image = img
  44. name.text = model!.subscribe_title!
  45. timeLabel.text = model!.pass_time
  46. content.text = model!.show_content
  47. goodImg.setFadeImage(with: model!.img)
  48. let priceT = model!.discount_price
  49. price.text = "¥"+(priceT ?? "")
  50. }
  51. }
  52. func configSubViews() {
  53. self.contentView.addSubview(icon)
  54. self.contentView.addSubview(name)
  55. self.contentView.addSubview(timeLabel)
  56. self.contentView.addSubview(content)
  57. self.contentView.addSubview(goodImg)
  58. self.goodImg.addSubview(price)
  59. icon.snp.makeConstraints { (make) in
  60. make.top.equalTo(self.contentView).offset(15)
  61. make.left.equalTo(15)
  62. make.width.height.equalTo(40)
  63. }
  64. goodImg.snp.makeConstraints { (make) in
  65. make.left.equalTo(icon.snp.left)
  66. make.width.height.equalTo(fitSize(x: 170))
  67. make.bottom.equalTo(self.contentView).offset(-10)
  68. }
  69. name.snp.makeConstraints { (make) in
  70. make.left.equalTo(icon.snp.right).offset(15)
  71. make.top.equalTo(icon.snp.top).offset(1)
  72. }
  73. timeLabel.snp.makeConstraints { (make) in
  74. make.left.equalTo(name.snp.left)
  75. make.bottom.equalTo(icon.snp.bottom).offset(-1)
  76. }
  77. content.snp.makeConstraints { (make) in
  78. make.left.equalTo(icon.snp.left)
  79. make.right.equalTo(-15)
  80. make.top.equalTo(icon.snp.bottom).offset(10)
  81. make.bottom.equalTo(goodImg.snp.top).offset(-10)
  82. }
  83. price.snp.makeConstraints { (make) in
  84. make.width.equalTo(60)
  85. make.height.equalTo(20)
  86. make.bottom.right.equalTo(0)
  87. }
  88. }
  89. lazy var icon: UIImageView = {
  90. let img = UIImageView()
  91. img.backgroundColor = UIColor.gloadGrayColor()
  92. return img
  93. }()
  94. lazy var name: UILabel = {
  95. let name = UILabel()
  96. name.textColor = UIColor.gloadRedColor()
  97. return name
  98. }()
  99. lazy var timeLabel: UILabel = {
  100. let time = UILabel()
  101. time.textColor = UIColor.hexadecimalColor(hexadecimal: "#666666")
  102. time.font = UIFont.systemFont(ofSize: 14)
  103. return time
  104. }()
  105. lazy var content: UILabel = {
  106. let content = UILabel()
  107. content.numberOfLines = 0
  108. content.font = UIFont.systemFont(ofSize: 17)
  109. content.textColor = UIColor.hexadecimalColor(hexadecimal: "#222222")
  110. return content
  111. }()
  112. lazy var goodImg: UIImageView = {
  113. let goodImg = UIImageView()
  114. goodImg.backgroundColor = UIColor.gloadGrayColor()
  115. return goodImg
  116. }()
  117. lazy var price: UILabel = {
  118. let price = UILabel()
  119. price.backgroundColor = UIColor.gloadRedColor()
  120. price.font = UIFont.systemFont(ofSize: 14)
  121. price.textColor = UIColor.white
  122. price.textAlignment = .center
  123. return price
  124. }()
  125. }