MineServiceTableViewCell.swift 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //
  2. // MineServiceTableViewCell.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/4/24.
  6. // Copyright © 2019 南鑫林. All rights reserved.
  7. //
  8. import UIKit
  9. class MineServiceTableViewCell: UITableViewCell {
  10. let titles = ["客服电话","个人资料","账号安全"]
  11. class func cellWith(tableView:UITableView,indexPath:IndexPath) -> MineServiceTableViewCell {
  12. let ID = "MineServiceTableViewCell"
  13. tableView.register(MineServiceTableViewCell.self, forCellReuseIdentifier: ID)
  14. let cell : MineServiceTableViewCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! MineServiceTableViewCell
  15. cell.indexPath = indexPath
  16. return cell
  17. }
  18. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  19. super.init(style: style, reuseIdentifier: reuseIdentifier)
  20. setupViews()
  21. setupLayouts()
  22. }
  23. required init?(coder aDecoder: NSCoder) {
  24. fatalError("init(coder:) has not been implemented")
  25. }
  26. var indexPath: IndexPath? {
  27. didSet {
  28. }
  29. }
  30. //MRAK: - 设置View
  31. private func setupViews() {
  32. self.selectionStyle = .none
  33. backgroundColor = kf7f8faColor
  34. addSubview(bgView)
  35. bgView.addSubview(topButton)
  36. topButton.addSubview(titleLabel)
  37. topButton.addSubview(lineLabel)
  38. bgView.addSubview(collectionView)
  39. }
  40. private func setupLayouts() {
  41. bgView.snp.makeConstraints { (make) in
  42. make.top.bottom.equalToSuperview()
  43. make.left.equalTo(14)
  44. make.right.equalTo(-14)
  45. }
  46. topButton.snp.makeConstraints { (make) in
  47. make.top.left.right.equalToSuperview()
  48. make.height.equalTo(44)
  49. }
  50. titleLabel.snp.makeConstraints { (make) in
  51. make.centerY.equalToSuperview()
  52. make.left.equalTo(10)
  53. }
  54. lineLabel.snp.makeConstraints { (make) in
  55. make.left.right.bottom.equalToSuperview()
  56. make.height.equalTo(0.5)
  57. }
  58. collectionView.snp.makeConstraints { (make) in
  59. make.top.equalTo(topButton.snp.bottom)
  60. make.left.equalTo(0)
  61. make.right.equalTo(0)
  62. make.height.equalTo(kScaleValue(value: 94))
  63. make.bottom.lessThanOrEqualTo(bgView)
  64. }
  65. }
  66. private lazy var bgView: UIView = {
  67. let bgView = UIView()
  68. bgView.backgroundColor = UIColor.white
  69. bgView.cornerRadius = 2.5
  70. bgView.masksToBounds = true
  71. return bgView
  72. }()
  73. private lazy var topButton: UIButton = {
  74. let topButton = UIButton(type: UIButton.ButtonType.custom)
  75. return topButton
  76. }()
  77. private lazy var titleLabel: UILabel = {
  78. let titleLabel = UILabel()
  79. titleLabel.text = "我的服务"
  80. titleLabel.textColor = k333333Color
  81. titleLabel.font = kMediumFont16
  82. return titleLabel
  83. }()
  84. private lazy var lineLabel: UILabel = {
  85. let lineLabel = UILabel()
  86. lineLabel.backgroundColor = kf5f5f5Color
  87. return lineLabel
  88. }()
  89. private lazy var collectionView: UICollectionView = {
  90. let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
  91. collectionView.backgroundColor = UIColor.white
  92. collectionView.delegate = self;
  93. collectionView.dataSource = self;
  94. collectionView.showsVerticalScrollIndicator = false
  95. collectionView.showsHorizontalScrollIndicator = false
  96. collectionView.cornerRadius = 2.5
  97. collectionView.masksToBounds = true
  98. return collectionView
  99. }()
  100. private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
  101. let collectionViewLayout = UICollectionViewFlowLayout.init()
  102. collectionViewLayout.minimumLineSpacing = 0
  103. collectionViewLayout.minimumInteritemSpacing = 0
  104. return collectionViewLayout
  105. }()
  106. //加载数据
  107. func reloadData() {
  108. //collectionView重新加载数据
  109. self.collectionView.reloadData()
  110. //更新collectionView的高度约束
  111. let contentSize = self.collectionView.collectionViewLayout.collectionViewContentSize
  112. collectionView.snp.remakeConstraints { (make) in
  113. make.top.equalTo(topButton.snp.bottom)
  114. make.left.right.equalToSuperview()
  115. make.height.equalTo(contentSize.height)
  116. make.bottom.lessThanOrEqualTo(bgView)
  117. }
  118. self.collectionView.collectionViewLayout.invalidateLayout()
  119. }
  120. }
  121. extension MineServiceTableViewCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
  122. func numberOfSections(in collectionView: UICollectionView) -> Int {
  123. return 1
  124. }
  125. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  126. return titles.count
  127. }
  128. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  129. let cell = MineServiceCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
  130. cell.titles = titles
  131. return cell
  132. }
  133. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  134. showSwiftProgressHUDInfo()
  135. }
  136. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  137. return CGSize(width:kScreenWidth-28, height: 48)
  138. }
  139. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
  140. return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  141. }
  142. }