IHHotelView.swift 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // IHHotelView.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2019/12/12.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. import JXPagingView
  10. class IHHotelView: UIView , UIScrollViewDelegate{
  11. var hotels :[HotelViewData]? {
  12. return Intermediate.share.hotels
  13. }
  14. lazy var tableView: UITableView = {
  15. let tableView = UITableView(frame:self.bounds, style: .plain)
  16. tableView.dataSource = self
  17. tableView.delegate = self
  18. return tableView
  19. }()
  20. var listViewDidScrollCallback: ((UIScrollView) -> ())?
  21. override init(frame: CGRect) {
  22. super.init(frame: frame)
  23. addSubview(tableView)
  24. self.backgroundColor = UIColor.white
  25. self.tableView.backgroundColor = UIColor.white
  26. tableView.separatorStyle = .none
  27. // for i in 0..<10 {
  28. // let cellid = "cell" + "\(i)"
  29. // tableView.register(UINib(nibName: "IHHotelCell", bundle: nil), forCellReuseIdentifier: cellid)
  30. // }
  31. }
  32. deinit {
  33. NotificationCenter.default.removeObserver(self)
  34. }
  35. required init?(coder: NSCoder) {
  36. fatalError("init(coder:) has not been implemented")
  37. }
  38. override func layoutSubviews() {
  39. super.layoutSubviews()
  40. tableView.frame = self.bounds
  41. self.tableView.reloadData()
  42. }
  43. }
  44. extension IHHotelView:UITableViewDataSource,UITableViewDelegate{
  45. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  46. return self.hotels?.count ?? 0
  47. }
  48. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  49. // let cellid = "cell" + "\(indexPath.row)"
  50. // let cell = tableView.dequeueReusableCell(withIdentifier: cellid) as! IHHotelCell
  51. //
  52. // cell.selectionStyle = .none
  53. // let lineView = IHDashView(strokeColor: UIColor(hexString: "C6CDD5", transparency: 0.5)?.cgColor, gap: 3, lineWith: 1)
  54. // cell.addSubview(lineView)
  55. let hotel = self.hotels![indexPath.row]
  56. var cell : IHHotelCell?
  57. if hotel.type! == "0" {
  58. cell = tableView.dequeueReusableCell(withIdentifier: "IHHotelCell") as? IHHotelCell
  59. if cell == nil{
  60. cell = Bundle.main.loadNibNamed("IHHotelCell", owner: nil, options: nil)?.first as? IHHotelCell
  61. }
  62. }else{
  63. cell = tableView.dequeueReusableCell(withIdentifier: "SchoolCell") as? IHHotelCell
  64. if cell == nil{
  65. cell = Bundle.main.loadNibNamed("IHHotelCell", owner: nil, options: nil)?.last as? IHHotelCell
  66. }
  67. }
  68. cell?.selectionStyle = .none
  69. for line in cell!.subviews {
  70. if line.isKind(of: IHDashView.self){
  71. line.removeFromSuperview()
  72. }
  73. }
  74. let lineView = IHDashView(strokeColor: UIColor(hexString: "C6CDD5", transparency: 0.5)?.cgColor, gap: 3, lineWith: 1)
  75. cell?.addSubview(lineView)
  76. //let hotel = self.hotels![indexPath.row]
  77. if hotel.alarmCount == "0" {
  78. if hotel.type! == "0"{
  79. lineView.frame = CGRect(x: 20, y: 230 - 52 - 1, width: KSCREENWIDTH - 40 , height: 1)
  80. }else{
  81. lineView.frame = CGRect(x: 20, y: 264 - 52 - 1, width: KSCREENWIDTH - 40 , height: 1)
  82. }
  83. }else{
  84. if hotel.type! == "0" {
  85. lineView.frame = CGRect(x: 20, y: 230 - 1, width: KSCREENWIDTH - 40 , height: 1)
  86. }else{
  87. lineView.frame = CGRect(x: 20, y: 264 - 1, width: KSCREENWIDTH - 40 , height: 1)
  88. }
  89. }
  90. cell!.hotel = hotel
  91. return cell!
  92. }
  93. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  94. let hotel = self.hotels![indexPath.row]
  95. if hotel.alarmCount == "0" {
  96. if hotel.type! == "0" {
  97. return 230 - 52
  98. }else{
  99. return 264 - 52
  100. }
  101. }else{
  102. if hotel.type! == "0" {
  103. return 230
  104. }else{
  105. return 264
  106. }
  107. }
  108. }
  109. func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
  110. let hotel = self.hotels![indexPath.row]
  111. if hotel.alarmCount == "0" {
  112. return 230 - 52
  113. }else{
  114. return 230
  115. }
  116. }
  117. func scrollViewDidScroll(_ scrollView: UIScrollView) {
  118. self.listViewDidScrollCallback?(scrollView)
  119. }
  120. }
  121. extension IHHotelView:JXPagingViewListViewDelegate{
  122. func listView() -> UIView {
  123. return self
  124. }
  125. func listScrollView() -> UIScrollView {
  126. return self.tableView
  127. }
  128. func listViewDidScrollCallback(callback: @escaping (UIScrollView) -> ()) {
  129. self.listViewDidScrollCallback = callback
  130. }
  131. }