1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- //
- // IHRoomListView.swift
- // Inhealth
- //
- // Created by weclouds on 2019/12/14.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- protocol IHRoomListViewDelegate : NSObjectProtocol {
- func roomListView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
- func roomListViewOpration(_ devId:String,devType:String,status:String,currentIndex:IndexPath)
- }
- class IHRoomListView: UIView {
- var devDatas :[DevData]?{
- didSet{
-
- }
- }
-
- weak var delegate : IHRoomListViewDelegate?
- lazy var collectionView: UICollectionView = {
- let layout = UICollectionViewFlowLayout()
- let cellwidth = (KSCREENWIDTH - 22.5 - 22.5 - 20) / 2
- layout.itemSize = CGSize(width: cellwidth, height: cellwidth)//设置cell的大小
- layout.minimumLineSpacing = 20
- layout.minimumInteritemSpacing = 10 //同一列最小间隔
- layout.scrollDirection = .vertical //纵向滚动
- layout.sectionInset = UIEdgeInsets(top: 20, left: 22.5, bottom: 20, right: 22.5)//设置内边距
- let collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: KSCREENWIDTH , height: KSCREENHEIGHT - KNavBarHeight - 50), collectionViewLayout: layout)
-
- collectionView.backgroundColor = UIColor.white
- collectionView.delegate = self
- collectionView.dataSource = self
- collectionView.showsHorizontalScrollIndicator = false
- collectionView.showsVerticalScrollIndicator = false
- collectionView.register(UINib(nibName: "IHIHRoomListCell", bundle: nil), forCellWithReuseIdentifier: "cell")
- return collectionView
- }()
-
- override init(frame: CGRect) {
- super.init(frame: frame)
- createUI()
- }
-
- func reloadData() {
-
- self.collectionView.reloadData()
-
- }
- func createUI() {
-
- addSubview(collectionView)
- }
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
-
-
- }
- extension IHRoomListView:UICollectionViewDelegate,UICollectionViewDataSource{
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return devDatas?.count ?? 0
- }
-
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as? IHIHRoomListCell
- let model = self.devDatas![indexPath.row]
- cell?.model = model
- cell?.delegate = self
- cell!.currentIndexPath = indexPath
- return cell!
- }
-
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- log.debug("点击了 \(indexPath.row)")
- if let delegate = delegate {
- delegate.roomListView(collectionView, didSelectItemAt: indexPath)
- }
- }
-
- }
- extension IHRoomListView :IHRoomListCellDelegate{
- func oprationSwitch(_ id: String, devType: String, status: String,currentIndex:IndexPath) {
- if let delegate = delegate {
- delegate.roomListViewOpration(id, devType: devType, status: status, currentIndex: currentIndex)
- }
- }
- }
|