| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- //
- // SBTRTStatusCell.swift
- // SolarBT
- //
- // Created by weclouds on 2019/1/28.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- class RealTimeItem: UIView {
-
- var valueString: String?{
- didSet{
- if let valueString = valueString {
- let strLength = valueString.count
-
- let attrStr = NSMutableAttributedString(string: valueString)
-
- let strfont : UIFont = UIFont.boldSystemFont(ofSize: 10)
-
- let attr2: [NSAttributedString.Key : Any] = [NSAttributedString.Key.font: strfont,NSAttributedString.Key.foregroundColor: UIColor(red: 0.53, green: 0.53, blue: 0.53, alpha: 1)]
- attrStr.addAttributes(attr2, range: NSRange(location: strLength - 1, length: 1))
- valueLabel.attributedText = attrStr
- }
- }
- }
-
- var title:String?{
- didSet{
- titleLabel.text = title
- }
- }
-
- var image : UIImage?{
- didSet{
- imageView.image = image
- }
- }
-
- lazy var titleLabel: UILabel = {
- let titleLabel = UILabel()
- titleLabel.font = UIFont(name: "苹方 中等", size: 12)
-
- titleLabel.textColor = UIColor(hexString: "222222")
- return titleLabel
- }()
-
- lazy var imageView: UIImageView = {
- let imageView = UIImageView()
- imageView.contentMode = UIView.ContentMode.scaleAspectFit
- return imageView
- }()
-
- lazy var valueLabel: UILabel = {
- let valueLabel = UILabel()
- // valueLabel.textAlignment = .center
- valueLabel.font = UIFont(name: "苹方 粗体", size: 18)
- valueLabel.textColor = UIColor(hexString: "222222")
- return valueLabel
- }()
- //ff0302009091fc
- override init(frame: CGRect) {
- super.init(frame: frame)
- createUI()
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
-
- func createUI() {
- //设置阴影
-
- addSubview(titleLabel)
- addSubview(imageView)
- addSubview(valueLabel)
-
-
- titleLabel.snp.makeConstraints { (make) in
- make.left.equalToSuperview().offset(15)
- make.top.equalToSuperview().offset(14)
- }
-
- imageView.snp.makeConstraints { (make) in
- make.right.equalToSuperview().offset(-14)
- make.top.equalToSuperview().offset(14)
- make.height.width.equalTo(14)
- }
-
- valueLabel.snp.makeConstraints { (make) in
- make.right.equalToSuperview().offset(0)
- make.left.equalToSuperview().offset(15)
- make.bottom.equalToSuperview().offset(-8)
- }
-
- self.layer.masksToBounds = true
- self.layer.cornerRadius = 4
-
-
- }
- }
- class SBTRTStatusCell: UITableViewCell,ZQTCustomSwitchDelegate {
-
- var isDemo :Bool?
-
- var valueModel: RealTimeValue?{
- didSet{
- item?.valueString = self.valueModel?.itemValue
- item1?.valueString = self.valueModel?.itemValue2
- item2?.valueString = self.valueModel?.itemValue3
- self.statusLabel.text = self.valueModel?.status
-
- if self.valueModel?.switchValue == "1" { // 逻辑开 -- > UI开
- self.aSwitch.isOn = true
- aSwitch.thumbTintColor = UIColor(hexString: "29B009")
- }else if self.valueModel?.switchValue == "0"{ //逻辑关 // UI关
- self.aSwitch.isOn = false
- aSwitch.thumbTintColor = UIColor(hexString: "A3A3A3")
- }
- }
- }
-
- var titleModel:ReatTimeName?{
- didSet{
- titleLabel.text = self.titleModel?.title
- item?.title = self.titleModel?.itemName1
- item1?.title = self.titleModel?.itemName2
- item2?.title = self.titleModel?.itemName3
- item?.image = UIImage(named:self.titleModel!.itemName1! )
- item1?.image = UIImage(named:self.titleModel!.itemName2!)
- item2?.image = UIImage(named:self.titleModel!.itemName3! )
- }
- }
-
- var item : RealTimeItem?
- var item1 :RealTimeItem?
- var item2 :RealTimeItem?
-
-
-
- @IBOutlet weak var titleLabel: UILabel!
- @IBOutlet weak var statusLabel: UILabel!
-
- var switchCallback : ((Bool)->Void)?
- var isSwitchHidden : Bool = true{
- didSet{
- self.aSwitch.isHidden = self.isSwitchHidden
- }
- }
-
- var isSwitchEnabled:Bool = false{
- didSet{
- self.aSwitch.isEnabled = self.isSwitchEnabled
- }
- }
- lazy var aSwitch :ZQTCustomSwitch = {
- let aSwift = ZQTCustomSwitch(frame: CGRect.zero, on: UIColor(hexString: "#F2F2F2"), offColor: UIColor(hexString: "#F2F2F2"), font: UIFont(name: PingFangSC_Medium, size: 9), ballSize: 17)
- aSwift?.onText = "On".da_localizedStr()
- aSwift?.offText = "Off".da_localizedStr()
-
- aSwift?.textColor = UIColor(hexString: "BFBFBF")
- aSwift?.thumbTintColor = UIColor(hexString: "29B009")
- aSwift?.isHidden = self.isSwitchHidden
-
- aSwift?.delegate = self
- return aSwift!
- }()
- @objc func switchPressed(_ aswitch: ZQTCustomSwitch) {
- // aswitch.isEnabled = false
- // if aswitch.isOn == true {
- // aSwitch.thumbTintColor = UIColor(hexString: "29B009")
- // }else{
- // aSwitch.thumbTintColor = UIColor(hexString: "A3A3A3")
- // }
- //
- // if self.isDemo == true {
- // if aswitch.isOn == true{
- // statusLabel.text = "Load_is_on".da_localizedStr()
- // }else{
- // statusLabel.text = "Load_is_off".da_localizedStr()
- // }
- // }
-
- }
-
- override func awakeFromNib() {
- super.awakeFromNib()
- // Initialization code
- createUI()
- aSwitch.addTarget(self, action: #selector(switchPressed), for: .valueChanged)
- }
- override func setSelected(_ selected: Bool, animated: Bool) {
- super.setSelected(selected, animated: animated)
- // Configure the view for the selected state
- }
-
- func createUI() {
- addSubview(aSwitch)
-
- aSwitch.snp.makeConstraints { (make) in
- make.top.equalToSuperview().offset(10)
- make.left.equalTo(self.titleLabel.snp.right).offset(15)
- make.width.equalTo(45)
- make.height.equalTo(22)
- }
- let itemWidth = (KSCREENWIDTH - 18 - 18 - 10 - 10) / 3
- let itemHeight = 61.0
- item = RealTimeItem(frame: CGRect(x: 18.0, y: 10.0 + 20 + 19 , width: Double(itemWidth), height: itemHeight))
- item?.valueString = "97.6V"
- item1 = RealTimeItem(frame: CGRect(x: Double(18.0 + 10 + itemWidth), y: 10.0 + 20 + 19 , width: Double(itemWidth), height: itemHeight))
- item1?.valueString = "271A"
- item2 = RealTimeItem(frame: CGRect(x: Double(18.0 + 10 + 10 + itemWidth + itemWidth), y: 10.0 + 20 + 19 , width: Double(itemWidth), height: itemHeight))
- item2?.valueString = "271W"
-
-
- self.contentView.addSubview(item!)
- self.contentView.addSubview(item1!)
- self.contentView.addSubview(item2!)
-
- item!.setShadow( UIColor(red: 0.84, green: 0.84, blue: 0.84, alpha: 0.33), shadowOffset: CGSize(width: 0, height: 2), shadowOpacity: 0.1, shadowRadius: 4)
- item1!.setShadow( UIColor(red: 0.84, green: 0.84, blue: 0.84, alpha: 0.33), shadowOffset: CGSize(width: 0, height: 2), shadowOpacity: 0.1, shadowRadius: 4)
- item2!.setShadow( UIColor(red: 0.84, green: 0.84, blue: 0.84, alpha: 0.33), shadowOffset: CGSize(width: 0, height: 2), shadowOpacity: 0.1, shadowRadius: 4)
- }
-
- func handleGestureRecognizerWithSwith(on isOn: Bool) {
- self.switchCallback!(isOn)
- }
-
- }
|