// // SBTParamSet_LoadCell.swift // SolarBT // // Created by weclouds on 2019/3/14. // Copyright © 2019 weclouds. All rights reserved. // import UIKit class SBTParamSet_LoadCell: UITableViewCell,UICollectionViewDelegate,UICollectionViewDataSource { var dataSource:[String]? = [String](){ didSet{ self.collectionView?.reloadData() } } let titleArr = ["Load_mode".da_localizedStr(),"Light_control_delay_time".da_localizedStr(),"Light_control_voltage".da_localizedStr()] var itemdidSelectedCallBack:((Int)->Void)? var collectionView:UICollectionView? override func awakeFromNib() { super.awakeFromNib() // Initialization code createUI() } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) // Configure the view for the selected state } //使用相应链:让事件传递到tableView的cell didSelect方法上 // //https://blog.csdn.net/feifeiwuxian/article/details/53503439 // override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { // // let view = super.hitTest(point, with: event) // if view != nil { // if (view?.isKind(of: UICollectionView.self))! || (view?.isKind(of: UICollectionViewCell.self))! { // return self // } // } // // return super.hitTest(point, with: event) // } // func createUI() { //打开用户点击 self.isUserInteractionEnabled = true let layout = UICollectionViewFlowLayout() let itemWidth = (KSCREENWIDTH - 25 * 3 ) / 2 layout.itemSize = CGSize(width:itemWidth , height: 89) layout.minimumLineSpacing = 12.5 //列间距 layout.minimumInteritemSpacing = 10 //行间距 layout.scrollDirection = .vertical collectionView = UICollectionView(frame: CGRect(x: 25, y: 15, width: KSCREENWIDTH - 50, height: 89 * 2 + 15 ), collectionViewLayout: layout) collectionView?.backgroundColor = UIColor.white collectionView?.showsVerticalScrollIndicator = false collectionView?.showsHorizontalScrollIndicator = false collectionView?.isScrollEnabled = false collectionView?.dataSource = self collectionView?.delegate = self collectionView?.bounces = false collectionView?.register(SBTParamSet_Item.self, forCellWithReuseIdentifier: "cell") addSubview(collectionView!) } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return dataSource!.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! SBTParamSet_Item cell.title = titleArr[indexPath.row] cell.subTitle = dataSource![indexPath.row] cell.subTitleLabel.font = UIFont(name: PingFangSC_Semibold, size: 16) if indexPath.row == 1 { cell.subTitle = dataSource![indexPath.row] }else if indexPath.row == 2{ cell.subTitle = dataSource![indexPath.row] } cell.backgroundColor = UIColor.white return cell } func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { itemdidSelectedCallBack!(indexPath.row) } }