IHClassGatewayView.swift 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // IHClassGatewayView.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2020/8/19.
  6. // Copyright © 2020 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. import JXSegmentedView
  10. import JXPagingView
  11. protocol IHClassGatewayViewDelete : NSObjectProtocol {
  12. func changeCtr(tag : Int)
  13. }
  14. class IHClassGatewayView: UIView {
  15. var contentView : UIView?
  16. var bottomView : UIView?
  17. weak var delete : IHClassGatewayViewDelete?
  18. override init(frame: CGRect) {
  19. super.init(frame: frame)
  20. self.backgroundColor = .white
  21. self.setupUI()
  22. }
  23. required init?(coder: NSCoder) {
  24. fatalError("init(coder:) has not been implemented")
  25. }
  26. }
  27. extension IHClassGatewayView {
  28. private func setupUI(){
  29. //h:811.5pt w: 376 ,h:74
  30. //设置底部的按键
  31. let bottomH = KSCREENHEIGHT * 74 / 811.5
  32. let bottomView = UIView.init(frame: CGRect.init(x: 0, y: KSCREENHEIGHT - bottomH, width: KSCREENWIDTH, height: bottomH))
  33. bottomView.backgroundColor = .white
  34. self.addSubview(bottomView)
  35. self.bottomView = bottomView
  36. //内容
  37. contentView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT - bottomH))
  38. self.addSubview(contentView!)
  39. let topLine = UIView.init(frame: CGRect.init(x: 0, y: 0.5, width: KSCREENWIDTH, height: 1))
  40. topLine.backgroundColor = .lightGray
  41. topLine.alpha = 0.5
  42. self.bottomView?.addSubview(topLine)
  43. //左边btn
  44. let classBtn = UIButton.init(frame: CGRect.init(x: 0, y: 4, width: KSCREENWIDTH * 0.5 - 0.5, height: bottomH * 0.6))
  45. classBtn.setImage(UIImage.init(named: "房间_未选中"), for: .normal)
  46. classBtn.setImage(UIImage.init(named: "房间_选中"), for: .selected)
  47. classBtn.setTitle("教室控制", for: .normal)
  48. classBtn.setTitleColor(UIColor.init(hexString: "#92A6C0"), for: .normal)
  49. classBtn.setTitleColor(UIColor.init(hexString: "##573F95"), for: .selected)
  50. classBtn.imageEdgeInsets = UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: 13)
  51. classBtn.isSelected = true
  52. classBtn.titleLabel?.font = UIFont.systemFont(ofSize: 12.0)
  53. classBtn.addTarget(self, action: #selector(choseClassCtr), for: .touchUpInside)
  54. classBtn.tag = 1
  55. bottomView.addSubview(classBtn)
  56. //中间线
  57. let line = UIView.init(frame: CGRect.init(x: classBtn.ly_maxX, y: 5, width: 1, height: bottomH * 0.5 - 6))
  58. line.alpha = 0.5
  59. line.backgroundColor = UIColor.init(hexString: "#C6CDD5")
  60. bottomView.addSubview(line)
  61. //右边
  62. let gatewayBtn = UIButton.init(frame: CGRect.init(x: line.ly_maxX, y: 5, width: KSCREENWIDTH * 0.5 - 0.5, height: bottomH * 0.6))
  63. gatewayBtn.setImage(UIImage.init(named: "设备_未选中"), for: .normal)
  64. gatewayBtn.setImage(UIImage.init(named: "设备_选中"), for: .selected)
  65. gatewayBtn.setTitle("网关配置", for: .normal)
  66. gatewayBtn.setTitleColor(UIColor.init(hexString: "#92A6C0"), for: .normal)
  67. gatewayBtn.setTitleColor(UIColor.init(hexString: "##573F95"), for: .selected)
  68. gatewayBtn.imageEdgeInsets = UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: 13)
  69. gatewayBtn.titleLabel?.font = UIFont.systemFont(ofSize: 12.0)
  70. gatewayBtn.addTarget(self, action: #selector(choseGatewayCtr), for: .touchUpInside)
  71. gatewayBtn.tag = 2
  72. bottomView.addSubview(gatewayBtn)
  73. }
  74. }
  75. extension IHClassGatewayView{
  76. @objc func choseClassCtr(btn : UIButton){
  77. btn.isSelected = !btn.isSelected
  78. for view in bottomView!.subviews {
  79. if view.tag == 2 {
  80. let gatewayBtn = view as! UIButton
  81. gatewayBtn.isSelected = !gatewayBtn.isSelected
  82. }
  83. }
  84. delete?.changeCtr(tag: btn.tag)
  85. }
  86. @objc func choseGatewayCtr(btn : UIButton){
  87. btn.isSelected = !btn.isSelected
  88. for view in bottomView!.subviews {
  89. if view.tag == 1 {
  90. let classBtn = view as! UIButton
  91. classBtn.isSelected = !classBtn.isSelected
  92. }
  93. }
  94. delete?.changeCtr(tag: btn.tag)
  95. }
  96. }