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.
 
 
 

175 lines
6.1 KiB

//
// HealthStepCell.swift
// Lookfit
//
// Created by lemo. on 2020/4/6.
// Copyright © 2020 Sheldon. All rights reserved.
//
import UIKit
class HealthStepCell: TableViewCell {
lazy var titleLabel: UILabel = {
let label = UILabel()
label.textColor = kHexColor(0x2A2A2A)
label.font = SystemMediumFont(18)
label.text = MultiLanguageKey.step.localized
return label
}()
lazy var dateLabel: UILabel = {
let label = UILabel()
label.textColor = kHexColor(0x888888)
label.font = SystemRegularFont(12)
label.text = DateClass.timestampToStr(Int(Date().timeIntervalSince1970), formatStr: "yyyy/MM/dd")
return label
}()
lazy var bgView: UIView = {
let view = UIView()
view.gradient(colors: [kHexColor(0x499FFF), kHexColor(0x004EFF)], locations: nil, autoLaoutFrame: CGRect(x: 0, y: 0, width: kScaleWidth(335), height: kScaleWidth(160)))
view.layer.cornerRadius = 10
view.layer.masksToBounds = true
return view
}()
lazy var stepCircleView: CircleView = {
let view = CircleView(lineWidth: 8, bottomColor: kHexColor(0xfffff, 0.3), progressColor: kHexColor(0xfffff), type: .doubleLine)
return view
}()
lazy var stepValue: UILabel = {
let label = UILabel()
label.font = DigitalFont(32)
label.textColor = kHexColor(0xffffff)
label.text = "0"
return label
}()
lazy var stepUnit: UILabel = {
let label = UILabel()
label.font = SystemRegularFont(12)
label.textColor = kHexColor(0xffffff)
label.text = MultiLanguageKey.stepTip.localized
return label
}()
lazy var dataCircleView: CircleView = {
let view = CircleView(lineWidth: 2, bottomColor: kHexColor(0xfffff, 0.3), type: .dottedLine)
return view
}()
lazy var stepCaloriesValue: UILabel = {
let label = UILabel()
label.font = SystemMediumFont(21)
label.textColor = kHexColor(0xffffff)
label.text = "0"
return label
}()
lazy var stepDistanceValue: UILabel = {
let label = UILabel()
label.font = SystemMediumFont(21)
label.textColor = kHexColor(0xffffff)
label.text = "0"
return label
}()
lazy var stepCalories: UILabel = {
let label = UILabel()
label.font = SystemRegularFont(12)
label.textColor = kHexColor(0x8C4B05)
label.text = MultiLanguageKey.kcal.localized
return label
}()
lazy var stepDistance: UILabel = {
let label = UILabel()
label.font = SystemRegularFont(12)
label.textColor = kHexColor(0x8C4B05)
label.text = MultiLanguageKey.km.localized
return label
}()
override func makeUI() {
super.makeUI()
selectionStyle = .none
addSubview(titleLabel)
addSubview(dateLabel)
addSubview(bgView)
bgView.addSubview(stepCircleView)
bgView.addSubview(dataCircleView)
stepCircleView.addSubview(stepValue)
stepCircleView.addSubview(stepUnit)
dataCircleView.addSubview(stepCaloriesValue)
dataCircleView.addSubview(stepDistanceValue)
dataCircleView.addSubview(stepCalories)
dataCircleView.addSubview(stepDistance)
layoutUI()
}
func layoutUI() {
titleLabel.snp.makeConstraints { (make) in
make.top.equalTo(kScaleWidth(20))
make.left.equalTo(25)
}
dateLabel.snp.makeConstraints { (make) in
make.bottom.equalTo(titleLabel.snp.bottom)
make.right.equalTo(-25)
}
bgView.snp.makeConstraints { (make) in
make.top.equalTo(titleLabel.snp.bottom).offset(10)
make.left.equalTo(20)
make.right.equalTo(-20)
make.height.equalTo(kScaleWidth(160))
}
stepCircleView.snp.makeConstraints { (make) in
make.centerY.equalToSuperview()
make.width.height.equalTo(kScaleWidth(130))
make.left.equalTo(kScaleWidth(28))
}
stepValue.snp.makeConstraints { (make) in
make.top.equalTo(kScaleWidth(39))
make.centerX.equalToSuperview()
}
stepUnit.snp.makeConstraints { (make) in
make.top.equalTo(stepValue.snp.bottom)
make.centerX.equalToSuperview()
}
dataCircleView.snp.makeConstraints { (make) in
make.centerY.equalToSuperview()
make.width.height.equalTo(kScaleWidth(130))
make.right.equalTo(-kScaleWidth(28))
}
stepCaloriesValue.snp.makeConstraints { (make) in
make.top.equalTo(kScaleWidth(34))
make.centerX.equalToSuperview()
}
stepDistanceValue.snp.makeConstraints { (make) in
make.top.equalTo(stepCaloriesValue.snp.bottom).offset(kScaleWidth(4))
make.centerX.equalToSuperview()
}
stepCalories.snp.makeConstraints { (make) in
make.lastBaseline.equalTo(stepCaloriesValue.snp.lastBaseline)
make.left.equalTo(stepCaloriesValue.snp.right).offset(5)
}
stepDistance.snp.makeConstraints { (make) in
make.lastBaseline.equalTo(stepDistanceValue.snp.lastBaseline)
make.left.equalTo(stepDistanceValue.snp.right).offset(5)
}
}
override func bind(model: ViewModel) {
super.bind(model: model)
guard let viewModel = model as? StepCellViewModels else { return }
viewModel.step
.bind(to: stepValue.rx.text)
.disposed(by: cellDisposeBag)
viewModel.calories
.bind(to: stepCaloriesValue.rx.text)
.disposed(by: cellDisposeBag)
viewModel.distance
.bind(to: stepDistanceValue.rx.text)
.disposed(by: cellDisposeBag)
viewModel.progress
.subscribe(onNext: { [weak self] (progress) in
self?.stepCircleView.updateProcess(process: Float(progress))
})
.disposed(by: cellDisposeBag)
viewModel.dateStr
.bind(to: dateLabel.rx.text)
.disposed(by: cellDisposeBag)
}
}