优惠券swift版马甲包

YMMainGoodCollectionCell.swift 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //
  2. // YMMainGoodCollectionCell.swift
  3. // MvpGoods
  4. //
  5. // Created by 小花 on 2019/4/9.
  6. // Copyright © 2019 MVP. All rights reserved.
  7. //
  8. import UIKit
  9. class YMMainGoodCollectionCell: UICollectionViewCell {
  10. // var imgView: UIImageView!
  11. // var titleLabel: UILabel?
  12. // var originPrice: UILabel?
  13. // var disPrice: UILabel?
  14. // var ticketBg: UIImageView?
  15. // var disPriceBg: UIImageView?
  16. // var disPriceType: UILabel?
  17. //
  18. convenience required init?(coder aDecoder: NSCoder) {
  19. self.init()
  20. }
  21. override init(frame: CGRect) {
  22. super.init(frame: frame)
  23. self.backgroundColor = UIColor.white
  24. configSubViews()
  25. }
  26. var model: YMMainGoodModel? {
  27. didSet {
  28. imgView.setFadeImage(with: model?.img)
  29. titleLabel.text = model?.title
  30. originPrice.text = "¥\(model?.price ?? ("未知"))"
  31. let ticket = model!.coupon_price
  32. ticketNum.text = "\(ticket ?? 0)"+"元"
  33. disPrice.text = "¥"+(model?.discount_price ?? "")
  34. }
  35. }
  36. func configSubViews() {
  37. self.contentView.addSubview(titleLabel)
  38. self.contentView.addSubview(imgView)
  39. self.contentView.addSubview(originPrice)
  40. self.contentView.addSubview(ticketBg)
  41. ticketBg.addSubview(ticketType)
  42. ticketBg.addSubview(ticketNum)
  43. self.contentView.addSubview(disPriceBg)
  44. disPriceBg.addSubview(disPrice)
  45. disPriceBg.addSubview(disText)
  46. imgView.snp.makeConstraints { (make) in
  47. make.left.equalTo(13)
  48. make.top.equalTo(10)
  49. make.bottom.equalTo(-10)
  50. make.width.equalTo(imgView.snp.height)
  51. }
  52. titleLabel.snp.makeConstraints { (make) in
  53. make.left.equalTo(imgView.snp.right).offset(8)
  54. make.right.equalTo(-10)
  55. make.top.equalTo(14)
  56. }
  57. originPrice.snp.makeConstraints { (make) in
  58. make.left.equalTo(titleLabel.snp.left)
  59. make.centerY.equalTo(imgView.snp.centerY)
  60. }
  61. ticketBg.snp.makeConstraints { (make) in
  62. make.left.equalTo(imgView.snp.right).offset(fitSize(x: 80))
  63. make.centerY.equalTo(imgView.snp.centerY)
  64. make.width.equalTo(62)
  65. make.height.equalTo(15)
  66. }
  67. ticketType.snp.makeConstraints { (make) in
  68. make.left.top.bottom.equalTo(0)
  69. make.width.equalTo(20)
  70. }
  71. ticketNum.snp.makeConstraints { (make) in
  72. make.top.right.bottom.equalTo(0)
  73. make.height.left.equalTo(20)
  74. }
  75. disPriceBg.snp.makeConstraints { (make) in
  76. make.left.equalTo(titleLabel)
  77. make.bottom.equalTo(imgView.snp.bottom).offset(-4)
  78. make.width.equalTo(102)
  79. make.height.equalTo(17)
  80. }
  81. disPrice.snp.makeConstraints { (make) in
  82. make.left.equalTo(5)
  83. make.top.equalTo(0)
  84. make.bottom.equalTo(0)
  85. make.width.equalTo(41)
  86. }
  87. disText.snp.makeConstraints { (make) in
  88. make.left.equalTo(51)
  89. make.top.right.bottom.equalTo(0)
  90. }
  91. }
  92. lazy var imgView: UIImageView = {
  93. let img = UIImageView()
  94. img.backgroundColor = UIColor.gloadGrayColor()
  95. return img
  96. }()
  97. lazy var titleLabel: UILabel = {
  98. let title = UILabel()
  99. title.textColor = UIColor.hexadecimalColor(hexadecimal: "#262626")
  100. title.font = UIFont.boldSystemFont(ofSize: 15)
  101. title.numberOfLines = 2
  102. return title
  103. }()
  104. lazy var originPrice: UILabel = {
  105. let price = UILabel()
  106. price.textColor = UIColor.gloadRedColor()
  107. price.font = UIFont.systemFont(ofSize: 16)
  108. return price;
  109. }()
  110. lazy var ticketBg: UIImageView = {
  111. let ticket = UIImageView()
  112. ticket.image = UIImage(named: "ticketBg")
  113. return ticket;
  114. }()
  115. lazy var ticketType: UILabel = {
  116. let type = UILabel()
  117. type.textColor = UIColor.white
  118. type.font = UIFont.systemFont(ofSize: 9)
  119. type.textAlignment = NSTextAlignment.center
  120. type.text = "券"
  121. return type
  122. }()
  123. lazy var ticketNum: UILabel = {
  124. let num = UILabel()
  125. num.textColor = UIColor.white
  126. num.font = UIFont.systemFont(ofSize: 9)
  127. num.textAlignment = NSTextAlignment.center
  128. return num
  129. }()
  130. lazy var disPriceBg: UIImageView = {
  131. let bg = UIImageView()
  132. bg.image = UIImage(named: "disBg")
  133. return bg
  134. }()
  135. lazy var disText: UILabel = {
  136. let text = UILabel()
  137. text.text = "券后价"
  138. text.textColor = UIColor.hexadecimalColor(hexadecimal: "#443F36")
  139. text.font = UIFont.systemFont(ofSize: 12)
  140. text.textAlignment = NSTextAlignment.center
  141. return text
  142. }()
  143. lazy var disPrice: UILabel = {
  144. let dis = UILabel()
  145. dis.textColor = UIColor.hexadecimalColor(hexadecimal: "#FFE4A0")
  146. // dis.textAlignment = NSTextAlignment.center
  147. dis.adjustsFontSizeToFitWidth = true
  148. dis.baselineAdjustment = UIBaselineAdjustment.alignCenters
  149. return dis
  150. }()
  151. }