SelfRecommendationCollectionViewCell.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // SelfRecommendationViewCollectionViewCell.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/4/19.
  6. // Copyright © 2019 南鑫林. All rights reserved.
  7. //
  8. import UIKit
  9. class SelfRecommendationCollectionViewCell: UICollectionViewCell {
  10. class func cellWith(collectionView:UICollectionView,indexPath:IndexPath) -> SelfRecommendationCollectionViewCell {
  11. let ID = "SelfRecommendationCollectionViewCell"
  12. collectionView.register(SelfRecommendationCollectionViewCell.self, forCellWithReuseIdentifier: ID)
  13. let cell : SelfRecommendationCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: ID, for: indexPath) as! SelfRecommendationCollectionViewCell
  14. cell.indexPath = indexPath
  15. return cell
  16. }
  17. //MARK: - indexPath
  18. var indexPath: IndexPath?{
  19. didSet {
  20. }
  21. }
  22. //MARK: - 初始化
  23. override init(frame: CGRect) {
  24. super.init(frame: frame)
  25. setupViews()
  26. setupLayouts()
  27. }
  28. required init?(coder aDecoder: NSCoder) {
  29. fatalError("init(coder:) has not been implemented")
  30. }
  31. //MARK: - 设置view
  32. private func setupViews() {
  33. backgroundColor = kffffffColor
  34. layer.cornerRadius = kScaleValue(value: 4)
  35. layer.masksToBounds = true
  36. addSubview(distanceLable)
  37. addSubview(titleLable)
  38. addSubview(goImageView)
  39. addSubview(addressLable)
  40. }
  41. private func setupLayouts() {
  42. titleLable.snp.makeConstraints { (make) in
  43. make.top.equalToSuperview().offset(kScaleValue(value: 19))
  44. make.left.equalToSuperview().offset(kScaleValue(value: 14))
  45. }
  46. distanceLable.snp.makeConstraints { (make) in
  47. make.top.equalTo(titleLable)
  48. make.right.equalToSuperview().offset(kScaleValue(value: -14))
  49. }
  50. addressLable.snp.makeConstraints { (make) in
  51. make.left.equalTo(titleLable)
  52. make.top.equalTo(titleLable.snp.bottom).offset(kScaleValue(value: 11))
  53. make.width.equalTo(kScaleValue(value: 260))
  54. make.bottom.equalToSuperview().offset(kScaleValue(value: -17))
  55. }
  56. goImageView.snp.makeConstraints { (make) in
  57. make.top.equalTo(addressLable)
  58. make.right.equalTo(distanceLable)
  59. make.size.equalTo(CGSize(width: 7, height: 11))
  60. }
  61. }
  62. private lazy var titleLable: UILabel = {
  63. let titleLable = UILabel()
  64. titleLable.textColor = k333333Color
  65. titleLable.font = kScaleBoldFont13
  66. titleLable.textAlignment = .left
  67. titleLable.numberOfLines = 0
  68. return titleLable
  69. }()
  70. private lazy var distanceLable: UILabel = {
  71. let distanceLable = UILabel()
  72. distanceLable.textColor = kFE352BColor
  73. distanceLable.font = kScaleRegularFont14
  74. return distanceLable
  75. }()
  76. private lazy var goImageView: UIImageView = {
  77. let goImageView = UIImageView()
  78. goImageView.image = kImage(name: "my_arrows_unfold")
  79. return goImageView
  80. }()
  81. private lazy var addressLable: UILabel = {
  82. let addressLable = UILabel()
  83. addressLable.text = "自提地址:陕西省西安市华侨城天鹅堡胡同村华侨城天鹅堡胡同村"
  84. addressLable.textColor = k666666Color
  85. addressLable.font = kScaleRegularFont13
  86. addressLable.textAlignment = .left
  87. addressLable.numberOfLines = 0
  88. return addressLable
  89. }()
  90. var selfMentionAddressModel : SelfMentionAddressModel? {
  91. didSet {
  92. titleLable.text = selfMentionAddressModel?.name
  93. distanceLable.text = String(describing: selfMentionAddressModel?.distance ?? "")
  94. addressLable.text = "自提地址:" + String(describing: selfMentionAddressModel?.address ?? "")
  95. }
  96. }
  97. }