123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794 |
- //
- // SBTParamSet_ChargerCell.swift
- // SolarBT
- //
- // Created by weclouds on 2019/3/14.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- class SBTextfield: UITextField {
- }
- //扩展NSRange,添加转换成Range的方法
- extension NSRange {
- func toRange(string: String) -> Range<String.Index> {
- let startIndex = string.index(string.startIndex, offsetBy: self.location)
- let endIndex = string.index(startIndex, offsetBy: self.length)
- return startIndex..<endIndex
- }
- }
- class SBTParamSetSwitch_Item: UICollectionViewCell {
-
- var sb_selected : Bool? = false {
- didSet{
- }
- }
-
- var differenceUI : Int? = 0{
- didSet{
- if let didfference = self.differenceUI {
- if didfference == 1{
- self.contentView.backgroundColor = UIColor(hexString: "#F1F1F1")
- // self.contentView.backgroundColor = UIColor.gray
- self.isUserInteractionEnabled = false
- }else{
- self.contentView.backgroundColor = UIColor(hexString: "#FFFFFF")
- //self.backgroundColor = UIColor.green
- self.isUserInteractionEnabled = true
- }
- }
- }
- }
-
- var switchCallback :((Bool)->Void)?
-
- var isOn :Bool?{
- didSet{
- if let isOn = self.isOn {
- if isOn == true {
- onButton.isSelected = true
- offButton.isSelected = false
- }else{
- onButton.isSelected = false
- offButton.isSelected = true
- }
- }
- }
- }
-
- var title : String?{
- didSet{
- titleLabel.text = title
- }
- }
-
- var canEdit : Bool? = false{
- didSet{
- if let canEdit = self.canEdit {
- onButton.isUserInteractionEnabled = canEdit
- offButton.isUserInteractionEnabled = canEdit
- }
-
- }
- }
-
- lazy var titleLabel: UILabel = {
- let titleLabel = UILabel()
- titleLabel.textColor = UIColor(hexString: "222222")
- titleLabel.numberOfLines = 0
- titleLabel.font = UIFont(name: PingFangSC_Regular, size: 11)
- return titleLabel
- }()
-
-
- lazy var onButton : UIButton = {
- let btn = UIButton()
- btn.titleLabel?.font = UIFont(name: PingFangSC_Semibold, size: 16)
- btn.setTitleColor(UIColor(hexString: "#B8B8B8"), for: .normal)
- btn.setTitleColor(UIColor(hexString: "#222222"), for: .selected)
- btn.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)
- btn.setTitle("ON", for: .normal)
- return btn
- }()
-
- lazy var offButton : UIButton = {
- let btn = UIButton()
- btn.titleLabel?.font = UIFont(name: PingFangSC_Semibold, size: 16)
- btn.setTitleColor(UIColor(hexString: "#B8B8B8"), for: .normal)
- btn.setTitleColor(UIColor(hexString: "#222222"), for: .selected)
- btn.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)
- btn.setTitle("OFF", for: .normal)
- return btn
- }()
-
- override init(frame: CGRect) {
- super.init(frame: frame)
- createUI()
- self.layer.borderColor = UIColor(hexString: "#D2D2D2")?.cgColor
- self.layer.borderWidth = 1
- self.layer.cornerRadius = 5
- self.layer.masksToBounds = true
- }
-
-
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- @objc func buttonClick(_ button: UIButton) {
- onButton.isSelected = false
- offButton.isSelected = false
- button.isSelected = true
-
- if self.canEdit == true {
- if onButton.isSelected == true{
- self.switchCallback!(true)
- }
- if offButton.isSelected == true{
- self.switchCallback!(false)
- }
- }
- }
-
- func createUI() {
- addSubview(titleLabel)
- addSubview(onButton)
- addSubview(offButton)
-
- titleLabel.snp.makeConstraints { (make) in
- make.top.equalToSuperview().offset(20)
- make.left.equalToSuperview().offset(15)
- make.right.equalToSuperview().offset(-15)
- }
-
- let line = UIView()
- line.backgroundColor = UIColor(hexString: "#CECECE")
- addSubview(line)
- line.snp.makeConstraints { (make) in
- make.centerX.equalToSuperview()
- make.bottom.equalToSuperview().offset(-18)
- make.width.equalTo(1)
- make.height.equalTo(19)
- }
-
- onButton.snp.makeConstraints { (make) in
- make.top.equalTo(titleLabel.snp.bottom).offset(8)
- make.bottom.equalToSuperview().offset(-8)
- make.left.equalToSuperview()
- make.right.equalTo(line.snp.left)
- }
-
- offButton.snp.makeConstraints { (make) in
- make.top.equalTo(titleLabel.snp.bottom).offset(8)
- make.bottom.equalToSuperview().offset(-8)
- make.right.equalToSuperview()
- make.left.equalTo(line.snp.right)
- }
-
- }
- }
- class SBTParamSet_balance_Item: UICollectionViewCell {
-
- var sb_selected : Bool? = false {
- didSet{
- // if let isselected = self.sb_selected {
- // if isselected == true{
- // //#29B009
- // self.layer.borderColor = UIColor(hexString: "#29B009")?.cgColor
- // }else{
- // self.layer.borderColor = UIColor(hexString: "#D2D2D2")?.cgColor
- // }
- // }
- }
- }
-
- var differenceUI : Int? = 0{
- didSet{
-
- if let didfference = self.differenceUI {
- if didfference == 1{
- self.contentView.backgroundColor = UIColor(hexString: "#F1F1F1")
- self.isUserInteractionEnabled = false
- }else{
- self.contentView.backgroundColor = UIColor(hexString: "#FFFFFF")
- self.isUserInteractionEnabled = true
- }
- }
- }
- }
-
-
-
- var canEdit : Bool = false {
- didSet{
-
- if self.canEdit == true {
-
- self.subTitleLabel.textColor = UIColor(hexString: "BBBBBB")
- // self.subTitleTextfield.isHidden = false
- // self.subTitleTextfield.placeholder = subTitle
- // self.subTitleLabel.isHidden = true
- }else{
- self.subTitleLabel.textColor = UIColor(hexString: "222222")
- // self.subTitleTextfield.isHidden = true
- // self.subTitleLabel.isHidden = false
- // self.isTapGuesture = false
- }
- }
- }
-
- var balanceTypeCallback:((Int)->Void)?
- var balanceType : Int? = -1{
- didSet{
- if self.balanceType != -1 {
- self.balanceTypeCallback!(self.balanceType!)
- }
- }
- }
-
- var title : String?{
- didSet{
- titleLabel.text = title
- }
- }
-
- var subTitle : String?{
- didSet{
- self.subTitleLabel.text = subTitle
- }
- }
-
- lazy var titleLabel: UILabel = {
- let titleLabel = UILabel()
- titleLabel.textColor = UIColor(hexString: "222222")
- titleLabel.numberOfLines = 0
- titleLabel.font = UIFont(name: PingFangSC_Regular, size: 11)
- return titleLabel
- }()
-
- lazy var subTitleLabel: UILabel = {
- let subTitleLabel = UILabel()
- subTitleLabel.textColor = UIColor(hexString: "222222")
- subTitleLabel.font = UIFont(name: PingFangSC_Semibold, size: 16)
- subTitleLabel.isHidden = false
- return subTitleLabel
- }()
-
-
-
-
- override init(frame: CGRect) {
- super.init(frame: frame)
- createUI()
- self.layer.borderColor = UIColor(hexString: "#D2D2D2")?.cgColor
- self.layer.borderWidth = 1
- self.layer.cornerRadius = 5
- self.layer.masksToBounds = true
- }
-
-
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
-
- func createUI() {
- addSubview(titleLabel)
- addSubview(subTitleLabel)
-
-
- titleLabel.snp.makeConstraints { (make) in
- make.top.equalToSuperview().offset(20)
- make.left.equalToSuperview().offset(15)
- make.right.equalToSuperview().offset(-15)
- }
- subTitleLabel.snp.makeConstraints { (make) in
- make.left.equalTo(titleLabel.snp.left)
- make.right.equalTo(titleLabel.snp.right)
- make.top.equalTo(titleLabel.snp.bottom).offset(8)
- }
-
-
- self.subTitleLabel.isUserInteractionEnabled = true
- let tap = UITapGestureRecognizer(target: self, action: #selector(tapAction))
- self.subTitleLabel.addGestureRecognizer(tap)
-
- }
-
- func sb_becameFirstResonder() {
- tapAction()
-
- }
-
- @objc func tapAction() {
- log.debug("手动均衡")
- let balances = ["Prohibited".da_localizedStr(),"Enable".da_localizedStr()]
- let balancePick = THScrollChooseView(question: balances, withDefaultDesc:"Prohibited".da_localizedStr())
- balancePick!.show()
- balancePick?.confirmBlock = {[weak self](selectedIndex) in
- log.debug(balances[selectedIndex])
-
-
- self?.subTitleLabel.text = balances[selectedIndex]
- self?.subTitleLabel.textColor = UIColor(hexString: "222222")
- self?.balanceType = selectedIndex
- }
- }
- }
- class SBTParamSet_Item: UICollectionViewCell , UITextFieldDelegate{
- var beginEditingCallback:(()->Void)?
-
- var ChangeCharactersCallback:((String?)->Void)?
-
- var sb_selected : Bool? = false {
- didSet{
-
- // if let isselected = self.sb_selected {
- // let view = subTitleTextfield.next as! SBTParamSet_Item
- // if isselected == true{
- //
- // //#29B009
- // view.layer.borderColor = UIColor(hexString: "#29B009")?.cgColor
- // }else{
- // view.layer.borderColor = UIColor(hexString: "#D2D2D2")?.cgColor
- // }
- // }
- }
- }
-
- //
- @objc func didselectedTexfield() {
- log.debug("测试 UITextField 的点击 ------\(subTitleTextfield.isEditing)")
-
- }
- var differenceUI : Int? = 0{
- didSet{
- if let didfference = self.differenceUI {
- if didfference == 1{
- self.contentView.backgroundColor = UIColor(hexString: "#F1F1F1")
- // self.contentView.backgroundColor = UIColor.gray
- self.isUserInteractionEnabled = false
-
- if self.canEdit == true {
- self.subTitleTextfield.isEnabled = false
- // self.subTitleTextfield.resignFirstResponder()
- }else{
- self.subTitleTextfield.isEnabled = true
- }
- }else{
- self.contentView.backgroundColor = UIColor(hexString: "#FFFFFF")
- self.isUserInteractionEnabled = true
-
- }
- }
- }
- }
-
-
- var resultCallback:((String,UITextField)->Void)?
-
- var isTapGuesture: Bool = false{
- didSet{
-
- }
- }
-
- var itemKeyboardType: UIKeyboardType? = .default{
- didSet {
- self.subTitleTextfield.keyboardType = self.itemKeyboardType!
- }
- }
- var keyboartypeISFloat: Bool? = false{
- didSet{
- if let keyboartypeISFloat = self.keyboartypeISFloat {
- if keyboartypeISFloat == true{
- // self.subTitleTextfield.keyboardType = .decimalPad
- }else{
- // self.subTitleTextfield.keyboardType = .numberPad
- }
- }
- }
- }
-
-
-
-
- var canEdit : Bool = false {
- didSet{
-
- if self.canEdit == true {
-
-
- self.subTitleTextfield.isHidden = false
- self.subTitleTextfield.placeholder = subTitle
- self.subTitleLabel.isHidden = true
- }else{
- self.subTitleTextfield.isHidden = true
- self.subTitleLabel.isHidden = false
- // self.isTapGuesture = false
- }
- }
- }
-
-
-
-
- var title : String?{
- didSet{
- titleLabel.text = title
-
- }
- }
-
- var subTitle : String?{
- didSet{
- self.subTitleLabel.text = subTitle
-
- }
- }
-
- lazy var titleLabel: UILabel = {
- let titleLabel = UILabel()
- titleLabel.textColor = UIColor(hexString: "222222")
- titleLabel.numberOfLines = 0
- titleLabel.font = UIFont(name: PingFangSC_Regular, size: 11)
- return titleLabel
- }()
-
- lazy var subTitleLabel: UILabel = {
- let subTitleLabel = UILabel()
- subTitleLabel.textColor = UIColor(hexString: "222222")
- subTitleLabel.font = UIFont(name: PingFangSC_Semibold, size: 16)
- subTitleLabel.isHidden = false
- return subTitleLabel
- }()
-
- lazy var subTitleTextfield: UITextField = {
- let subTitle = UITextField()
- subTitle.textColor = UIColor(hexString: "222222")
- // subTitle.backgroundColor = UIColor.blue
- subTitle.isHidden = true
- subTitle.addDoneOnKeyboardWithTarget(self, action: #selector(self.doneAction(_:)), shouldShowPlaceholder: true)
- subTitle.keyboardToolbar.doneBarButton.setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor(hexString: "222222") as Any], for: .normal)
-
-
- subTitle.font = UIFont(name: PingFangSC_Semibold, size: 16)
- return subTitle
- }()
-
- @objc func doneAction(_ sender : UITextField!) {
- self.endEditing(true)
- }
- override init(frame: CGRect) {
- super.init(frame: frame)
- createUI()
- self.layer.borderColor = UIColor(hexString: "#D2D2D2")?.cgColor
- self.layer.borderWidth = 1
- self.layer.cornerRadius = 5
- self.layer.masksToBounds = true
- self.subTitleTextfield.delegate = self
-
- }
-
-
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- //输入完成
- func textFieldDidEndEditing(_ textField: UITextField) {
-
-
- if textField.text != ""{
- let textFloat = Float(textField.text!)
- if (textFloat == nil){
- makeToast("please_enter_number".da_localizedStr())
- textField.text = ""
- }else{
- self.resultCallback!(textField.text!,textField)
-
- // if let ChangeCharactersCallback = self.ChangeCharactersCallback {
- // ChangeCharactersCallback(textField.text)
- // }
- }
-
- }
- }
-
-
-
- func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
- // if beginEditingCallback != nil{
- // self.beginEditingCallback!()
- // }
-
- // self.sb_selected = true
-
-
- return true
- }
-
-
-
- func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
-
-
- // let currentText = textField.text ?? ""
- // let newText = currentText.replacingCharacters(in:
- // range.toRange(string: currentText), with: string)
-
-
-
- if self.keyboartypeISFloat == true {
-
- let toString = (textField.text! as NSString).replacingCharacters(in: range, with: string)
- let expression = "^[0-9]*((\\\\.|,)[0-9]{0,1})?$"// 正则表达式 保留一位小数
- let regex = try! NSRegularExpression(pattern: expression, options: NSRegularExpression.Options.allowCommentsAndWhitespace)
- let numberOfMatches = regex.numberOfMatches(in: toString, options:NSRegularExpression.MatchingOptions.reportProgress, range: NSMakeRange(0, (toString as NSString).length))
- return numberOfMatches != 0
- }
- return true
- }
-
- func createUI() {
- addSubview(titleLabel)
- addSubview(subTitleLabel)
- addSubview(subTitleTextfield)
-
- titleLabel.snp.makeConstraints { (make) in
- make.top.equalToSuperview().offset(20)
- make.left.equalToSuperview().offset(15)
- make.right.equalToSuperview().offset(-15)
- }
- subTitleLabel.snp.makeConstraints { (make) in
- make.left.equalTo(titleLabel.snp.left)
- make.top.equalTo(titleLabel.snp.bottom).offset(8)
- }
-
- subTitleTextfield.snp.makeConstraints { (make) in
- make.left.equalTo(titleLabel.snp.left)
- make.top.equalTo(titleLabel.snp.bottom).offset(8)
- make.right.equalToSuperview().offset(-15)
- make.bottom.equalToSuperview().offset(-8)
- }
-
-
- }
- }
- class SBTParamSet_ChargerCell: UITableViewCell,UICollectionViewDelegate,UICollectionViewDataSource {
- var isOld: Bool?
-
- //放大倍数
- var Multiple : Float? // 默认为1倍
-
- var difeffrentUIArr : [Int]? = [Int]()
-
- var defaultData : [Double]? = [Double]()
-
- var CellBatteryType :BatteryType? = .USER{
- didSet{
- if self.isOld == true {
- if let batteryType = self.CellBatteryType {
- switch batteryType {
- case .USER:
- self.difeffrentUIArr = [1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1]
- //self.defaultData = [16.0,15.5,14.4,13.8,13.2,120,-3]
- case .SLD:
- self.difeffrentUIArr = [1,1,1,1, 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1]
- case .FLD:
- self.difeffrentUIArr = [1,1,1,1, 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1]
- case .GEL:
- self.difeffrentUIArr = [1,1,1,1, 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1]
- case .LI:
- self.difeffrentUIArr = [1,1,1,1, 1,1,0,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1]
-
- }
- }
- }else{
- if let batteryType = self.CellBatteryType {
- switch batteryType {
- case .USER:
- self.difeffrentUIArr = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
- //self.defaultData = [16.0,15.5,14.4,13.8,13.2,120,-3]
- case .SLD:
- self.difeffrentUIArr = [0,0,0,0, 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,0]
- case .FLD:
- self.difeffrentUIArr = [0,0,0,0, 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,0]
- case .GEL:
- self.difeffrentUIArr = [0,0,0,0, 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,0]
- case .LI:
- self.difeffrentUIArr = [0,0,0,0, 1,1,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,0]
-
- }
- }
- }
-
-
- }
- }
- var dataSources:[String]? = [String](){
- didSet{
- self.collectionView?.reloadData()
- }
- }
-
- var a :String?{
- didSet{
- log.debug("====================传过来\(a!)")
- }
- }
- func getData(_ dataSource:[String]?) {
-
- }
-
-
- var itemdidSelectedCallBack:((IndexPath)->Void)?
- var collectionView:UICollectionView?
- var canEdit: Bool? = false{
- didSet{
-
- }
- }
-
- var itemTitles = [String]()
- // override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- // super.init(style: style, reuseIdentifier: reuseIdentifier)
- // // dataSources = [String]()
- // createUI()
- // }
- //
- // required init?(coder aDecoder: NSCoder) {
- // fatalError("init(coder:) has not been implemented")
- // }
-
- override func awakeFromNib() {
- super.awakeFromNib()
- NotificationCenter.default.addObserver(self, selector: #selector(notifionCationSetBatteryType), name: NSNotification.Name(rawValue: kNotifionCationSetBatteryType), object: nil)
- let def = UserDefaults.standard
- let istemp = def.value(forKey: TEMPISCENTIGRADE) as? String
- var Upper_limit_of_charge_temperature = "Upper_limit_of_charge_temperature".da_localizedStr() + "(℃)"
- var Lower_limit_of_charge_temperature = "Lower_limit_of_charge_temperature".da_localizedStr() + "(℃)"
- var Upper_limit_of_discharge_temperature = "Upper_limit_of_discharge_temperature".da_localizedStr() + "(℃)"
- var Lower_limit_of_discharge_temperature = "Lower_limit_of_discharge_temperature".da_localizedStr() + "(℃)"
- if istemp == "0"{
- Upper_limit_of_charge_temperature = "Upper_limit_of_charge_temperature".da_localizedStr() + "(℉)"
- Lower_limit_of_charge_temperature = "Lower_limit_of_charge_temperature".da_localizedStr() + "(℉)"
- Upper_limit_of_discharge_temperature = "Upper_limit_of_discharge_temperature".da_localizedStr() + "(℉)"
- Lower_limit_of_discharge_temperature = "Lower_limit_of_discharge_temperature".da_localizedStr() + "(℉)"
- }else if istemp == "1"{
- Upper_limit_of_charge_temperature = "Upper_limit_of_charge_temperature".da_localizedStr() + "(℃)"
- Lower_limit_of_charge_temperature = "Lower_limit_of_charge_temperature".da_localizedStr() + "(℃)"
- Upper_limit_of_discharge_temperature = "Upper_limit_of_discharge_temperature".da_localizedStr() + "(℃)"
- Lower_limit_of_discharge_temperature = "Lower_limit_of_discharge_temperature".da_localizedStr() + "(℃)"
- }
- itemTitles = ["Maximum_charge_current(A)".da_localizedStr(),
- "Charge_on/off".da_localizedStr(),
- Upper_limit_of_charge_temperature,
- Lower_limit_of_charge_temperature,
- "Overvoltage".da_localizedStr(),
-
- "Limited_charge_voltage".da_localizedStr(),
- "Boost_charge_voltage".da_localizedStr(),
- "Floating_charge_voltage".da_localizedStr(),
- "Boost_charge_return_voltage".da_localizedStr(),
- "Boost_charge_time".da_localizedStr(),
- "Temperature_compensation_coefficient".da_localizedStr(),
- "Equalizing_charge_voltage".da_localizedStr(),
- "Equalizing_charge_time".da_localizedStr(),
- "Equalizing_charge_interval".da_localizedStr(),
- "Manual_equalizing".da_localizedStr(),
- "Over_discharge_return_voltage".da_localizedStr(),
- "Undervoltage_warning_voltage".da_localizedStr(),
- "Over_discharge_voltage".da_localizedStr(),
- "Discharge_cutoff_voltage".da_localizedStr(),
- "Over_discharge_delay_time".da_localizedStr(),
- Upper_limit_of_discharge_temperature,
- Lower_limit_of_discharge_temperature]
- createUI()
-
- }
-
- override func setSelected(_ selected: Bool, animated: Bool) {
- super.setSelected(selected, animated: animated)
- // Configure the view for the selected state
- }
- // 01 10ve01d0005a7cc
-
- //设置区别颜色
- @objc func notifionCationSetBatteryType() {
-
- let batteryType = AppShare.batteryType
- log.debug("电池类型啊啊啊啊啊啊啊啊啊 -- \(batteryType! )")
- self.CellBatteryType = batteryType
- self.collectionView?.reloadData()
- }
-
- func createUI() {
- 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: 110 * 10 + 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
- for i in 0..<22 {
- if i != 1 {
- let identifier = "cell" + "\(i)"
- collectionView?.register(SBTParamSet_Item.self, forCellWithReuseIdentifier: identifier)
- }
- }
-
- collectionView?.register(SBTParamSetSwitch_Item.self, forCellWithReuseIdentifier: "cell1")
- addSubview(collectionView!)
-
- }
-
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return self.dataSources!.count
-
- }
-
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- //
- // log.debug(difeffrentUIArr)
- if indexPath.row == 1 {
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell1", for: indexPath) as! SBTParamSetSwitch_Item
-
- cell.title = itemTitles[indexPath.row]
- cell.differenceUI = self.difeffrentUIArr![indexPath.row]
- // log.debug("UI显示不一样-----\(self.difeffrentUIArr![indexPath.row])")
- let cmd = dataSources![indexPath.row]
- if cmd == "开" || cmd == "On"{
- cell.isOn = true
- }else if cmd == "关" || cmd == "Off"{
- cell.isOn = false
- }
- cell.canEdit = canEdit
- cell.backgroundColor = UIColor.white
- return cell
- }
- else{
- let identifier = "cell" + "\(indexPath.row)"
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) as! SBTParamSet_Item
- cell.title = itemTitles[indexPath.row]
- cell.differenceUI = self.difeffrentUIArr![indexPath.row]
- cell.subTitle = dataSources![indexPath.row]
- cell.backgroundColor = UIColor.white
- return cell
- }
-
- }
-
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- itemdidSelectedCallBack!(indexPath)
-
- }
- }
|