You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
159 lines
6.0 KiB
159 lines
6.0 KiB
![]()
2 years ago
|
//
|
||
|
// HealthFormView.swift
|
||
|
// HPlusFit
|
||
|
//
|
||
|
// Created by lemo. on 2019/9/24.
|
||
|
// Copyright © 2019 lemo. All rights reserved.
|
||
|
//
|
||
|
|
||
|
|
||
|
import UIKit
|
||
|
|
||
|
struct HealthFormModel {
|
||
|
let oneValue: String
|
||
|
let twoValue: String
|
||
|
let threeValue: String
|
||
|
let fourValue: String
|
||
|
}
|
||
|
|
||
|
class HealthFormView: UIView, NibLoadable {
|
||
|
|
||
|
@IBOutlet weak var tip1Label: UILabel!
|
||
|
@IBOutlet weak var tip2Label: UILabel!
|
||
|
@IBOutlet weak var tip3Label: UILabel!
|
||
|
@IBOutlet weak var tip4Label: UILabel!
|
||
|
|
||
|
@IBOutlet weak var totalSteps: UILabel!
|
||
|
@IBOutlet weak var totalDistance: UILabel!
|
||
|
@IBOutlet weak var totalTime: UILabel!
|
||
|
@IBOutlet weak var totalEnergy: UILabel!
|
||
|
|
||
|
@IBOutlet weak var unit1Label: UILabel!
|
||
|
@IBOutlet weak var unit2Label: UILabel!
|
||
|
@IBOutlet weak var unit3Label: UILabel!
|
||
|
@IBOutlet weak var unit4Label: UILabel!
|
||
|
|
||
|
@IBOutlet weak var hView: UIView!
|
||
|
@IBOutlet weak var sView: UIView!
|
||
|
|
||
|
private var type: HealthType = .step
|
||
|
|
||
|
|
||
|
lazy var views: UIView = {
|
||
|
let views = UIView()
|
||
|
views.backgroundColor = kHexColor(0xEAEAEA)
|
||
|
return views
|
||
|
}()
|
||
|
|
||
|
|
||
|
override func awakeFromNib() {
|
||
|
super.awakeFromNib()
|
||
|
|
||
|
addSubview(views)
|
||
|
// 文本修改
|
||
|
totalSteps.font = UIFont(name: "DINAlternate-Bold", size: kScaleWidth(24))
|
||
|
totalDistance.font = UIFont(name: "DINAlternate-Bold", size: kScaleWidth(24))
|
||
|
totalTime.font = UIFont(name: "DINAlternate-Bold", size: kScaleWidth(24))
|
||
|
totalEnergy.font = UIFont(name: "DINAlternate-Bold", size: kScaleWidth(24))
|
||
|
// 按比例适配
|
||
|
for subView in self.subviews {
|
||
|
for constrain in subView.constraints {
|
||
|
constrain.constant = kScaleWidth(constrain.constant)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func configUI(type: HealthType) {
|
||
|
self.type = type
|
||
|
switch type {
|
||
|
case .step:
|
||
|
unit3Label.text = "(\(MultiLanguageKey.min.localized))"
|
||
|
unit4Label.text = MultiLanguageKey.kcal.localized
|
||
|
tip1Label.text = MultiLanguageKey.maxStep.localized
|
||
|
tip2Label.text = MultiLanguageKey.kmMileage.localized
|
||
|
tip3Label.text = MultiLanguageKey.duration.localized
|
||
|
tip4Label.text = MultiLanguageKey.consume.localized
|
||
|
case .sleep:
|
||
|
unit1Label.text = MultiLanguageKey.hour.localized
|
||
|
unit2Label.text = MultiLanguageKey.hour.localized
|
||
|
unit3Label.text = MultiLanguageKey.hour.localized
|
||
|
tip1Label.text = MultiLanguageKey.deepSleep.localized
|
||
|
tip2Label.text = MultiLanguageKey.shallowSleep.localized
|
||
|
tip3Label.text = MultiLanguageKey.sleepDuration.localized
|
||
|
// tip4Label.text = MultiLanguageKey.awakeNumber.localized
|
||
|
tip4Label.text = MultiLanguageKey.awakeDuration.localized
|
||
|
case .heartRate:
|
||
|
unit1Label.text = MultiLanguageKey.hrUnit.localized
|
||
|
unit2Label.text = MultiLanguageKey.hrUnit.localized
|
||
|
unit3Label.text = MultiLanguageKey.hrUnit.localized
|
||
|
tip1Label.text = MultiLanguageKey.avgHr.localized
|
||
|
tip2Label.text = MultiLanguageKey.maxHr.localized
|
||
|
tip3Label.text = MultiLanguageKey.minHr.localized
|
||
|
tip4Label.text = ""
|
||
|
case .temperature:
|
||
|
unit1Label.text = MultiLanguageKey.centigrade.localized
|
||
|
unit2Label.text = MultiLanguageKey.centigrade.localized
|
||
|
unit3Label.text = MultiLanguageKey.centigrade.localized
|
||
|
tip1Label.text = MultiLanguageKey.avgTemperature.localized
|
||
|
tip2Label.text = MultiLanguageKey.maxTemperature.localized
|
||
|
tip3Label.text = MultiLanguageKey.minTemperature.localized
|
||
|
tip4Label.text = ""
|
||
|
case .bloodPressure:
|
||
|
unit1Label.text = MultiLanguageKey.bloodPressureUnit.localized
|
||
|
unit2Label.text = MultiLanguageKey.bloodPressureUnit.localized
|
||
|
unit3Label.text = MultiLanguageKey.bloodPressureUnit.localized
|
||
|
unit4Label.text = MultiLanguageKey.bloodPressureUnit.localized
|
||
|
tip1Label.text = MultiLanguageKey.avgSBP.localized
|
||
|
tip2Label.text = MultiLanguageKey.avgDBP.localized
|
||
|
tip3Label.text = MultiLanguageKey.maxSBP.localized
|
||
|
tip4Label.text = MultiLanguageKey.maxDBP.localized
|
||
|
hView.isHidden = true
|
||
|
sView.isHidden = true
|
||
|
views.snp.makeConstraints { make in
|
||
|
make.centerX.equalToSuperview()
|
||
|
make.top.equalTo(15)
|
||
|
make.size.equalTo(CGSize(width: 1, height: 80))
|
||
|
}
|
||
|
case .bloodOxygen:
|
||
|
unit1Label.text = MultiLanguageKey.bloodOxygenUnit.localized
|
||
|
unit2Label.text = MultiLanguageKey.bloodOxygenUnit.localized
|
||
|
unit3Label.text = MultiLanguageKey.bloodOxygenUnit.localized
|
||
|
tip1Label.text = MultiLanguageKey.avgBloodOxygen.localized
|
||
|
tip2Label.text = MultiLanguageKey.maxBloodOxygen.localized
|
||
|
tip3Label.text = MultiLanguageKey.minBloodOxygen.localized
|
||
|
tip4Label.text = ""
|
||
|
default:
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fileprivate func bingUpdeFormView(model: HealthFormModel?) {
|
||
|
var defaultFout = "--"
|
||
|
switch type {
|
||
|
case .heartRate, .temperature, .bloodOxygen:
|
||
|
defaultFout = ""
|
||
|
default: break
|
||
|
}
|
||
|
guard let formModel = model else {
|
||
|
self.totalSteps.text = "--"
|
||
|
self.totalDistance.text = "--"
|
||
|
self.totalTime.text = type == .bloodPressure ? "" : "--"
|
||
|
self.totalEnergy.text = type == .bloodPressure ? "" : defaultFout
|
||
|
return
|
||
|
}
|
||
|
totalSteps.text = formModel.oneValue
|
||
|
totalDistance.text = formModel.twoValue
|
||
|
totalTime.text = formModel.threeValue
|
||
|
totalEnergy.text = formModel.fourValue
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
extension Reactive where Base: HealthFormView {
|
||
|
func formDataSource() -> Binder<HealthFormModel?> {
|
||
|
return Binder(self.base, binding: { (formView, model) in
|
||
|
formView.bingUpdeFormView(model: model)
|
||
|
})
|
||
|
}
|
||
|
}
|