SBTParamSet_LoadCell.swift 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // SBTParamSet_LoadCell.swift
  3. // SolarBT
  4. //
  5. // Created by weclouds on 2019/3/14.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. class SBTParamSet_LoadCell: UITableViewCell,UICollectionViewDelegate,UICollectionViewDataSource {
  10. var dataSource:[String]? = [String](){
  11. didSet{
  12. self.collectionView?.reloadData()
  13. }
  14. }
  15. let titleArr = ["Load_mode".da_localizedStr(),"Light_control_delay_time".da_localizedStr(),"Light_control_voltage".da_localizedStr()]
  16. var itemdidSelectedCallBack:((Int)->Void)?
  17. var collectionView:UICollectionView?
  18. override func awakeFromNib() {
  19. super.awakeFromNib()
  20. // Initialization code
  21. createUI()
  22. }
  23. override func setSelected(_ selected: Bool, animated: Bool) {
  24. super.setSelected(selected, animated: animated)
  25. // Configure the view for the selected state
  26. }
  27. //使用相应链:让事件传递到tableView的cell didSelect方法上
  28. // //https://blog.csdn.net/feifeiwuxian/article/details/53503439
  29. // override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
  30. //
  31. // let view = super.hitTest(point, with: event)
  32. // if view != nil {
  33. // if (view?.isKind(of: UICollectionView.self))! || (view?.isKind(of: UICollectionViewCell.self))! {
  34. // return self
  35. // }
  36. // }
  37. //
  38. // return super.hitTest(point, with: event)
  39. // }
  40. //
  41. func createUI() {
  42. //打开用户点击
  43. self.isUserInteractionEnabled = true
  44. let layout = UICollectionViewFlowLayout()
  45. let itemWidth = (KSCREENWIDTH - 25 * 3 ) / 2
  46. layout.itemSize = CGSize(width:itemWidth , height: 89)
  47. layout.minimumLineSpacing = 12.5 //列间距
  48. layout.minimumInteritemSpacing = 10 //行间距
  49. layout.scrollDirection = .vertical
  50. collectionView = UICollectionView(frame: CGRect(x: 25, y: 15, width: KSCREENWIDTH - 50, height: 89 * 2 + 15 ), collectionViewLayout: layout)
  51. collectionView?.backgroundColor = UIColor.white
  52. collectionView?.showsVerticalScrollIndicator = false
  53. collectionView?.showsHorizontalScrollIndicator = false
  54. collectionView?.isScrollEnabled = false
  55. collectionView?.dataSource = self
  56. collectionView?.delegate = self
  57. collectionView?.bounces = false
  58. collectionView?.register(SBTParamSet_Item.self, forCellWithReuseIdentifier: "cell")
  59. addSubview(collectionView!)
  60. }
  61. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  62. return dataSource!.count
  63. }
  64. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  65. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! SBTParamSet_Item
  66. cell.title = titleArr[indexPath.row]
  67. cell.subTitle = dataSource![indexPath.row]
  68. cell.subTitleLabel.font = UIFont(name: PingFangSC_Semibold, size: 16)
  69. if indexPath.row == 1 {
  70. cell.subTitle = dataSource![indexPath.row]
  71. }else if indexPath.row == 2{
  72. cell.subTitle = dataSource![indexPath.row]
  73. }
  74. cell.backgroundColor = UIColor.white
  75. return cell
  76. }
  77. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  78. itemdidSelectedCallBack!(indexPath.row)
  79. }
  80. }