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.
79 lines
3.0 KiB
79 lines
3.0 KiB
![]()
2 years ago
|
//
|
||
|
// SportHeaderView.swift
|
||
|
// HPlusFit
|
||
|
//
|
||
|
// Created by lemo. on 2019/9/17.
|
||
|
// Copyright © 2019 lemo. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import UIKit
|
||
|
|
||
|
class SportHeaderView: UIView {
|
||
|
|
||
|
@IBOutlet weak var dataBgView: UIView!
|
||
|
@IBOutlet weak var distanceBgView: UIView!
|
||
|
@IBOutlet weak var distanceTipLabel: UILabel!
|
||
|
@IBOutlet weak var distanceValueLabel: UILabel!
|
||
|
@IBOutlet weak var distanceUnitLabel: UILabel!
|
||
|
|
||
|
@IBOutlet weak var countBgView: UIView!
|
||
|
@IBOutlet weak var countTipLabel: UILabel!
|
||
|
@IBOutlet weak var countValueLabel: UILabel!
|
||
|
@IBOutlet weak var countUnitLabel: UILabel!
|
||
|
|
||
|
@IBOutlet weak var durationBgView: UIView!
|
||
|
@IBOutlet weak var durationTipLabel: UILabel!
|
||
|
@IBOutlet weak var durationValueLabel: UILabel!
|
||
|
|
||
|
@IBOutlet weak var caloriesBgView: UIView!
|
||
|
@IBOutlet weak var caloriesTipLabel: UILabel!
|
||
|
@IBOutlet weak var caloriesValueLabel: UILabel!
|
||
|
|
||
|
@IBOutlet weak var sportListLabel: UILabel!
|
||
|
|
||
|
override func awakeFromNib() {
|
||
|
super.awakeFromNib()
|
||
|
dataBgView.layer.cornerRadius = 10
|
||
|
dataBgView.layer.shadowOffset = CGSize(width: 0, height: 1.5)
|
||
|
dataBgView.layer.shadowOpacity = 1
|
||
|
dataBgView.layer.shadowRadius = 7
|
||
|
dataBgView.layer.shadowColor = UIColor(red: 0.15, green: 0.54, blue: 0.82, alpha: 0.2).cgColor
|
||
|
bgViewStyle(view: distanceBgView, color: kHexColor(0xFFCC9C))
|
||
|
bgViewStyle(view: countBgView, color: kHexColor(0x80D0FF))
|
||
|
bgViewStyle(view: durationBgView, color: kHexColor(0x9CAFFF))
|
||
|
bgViewStyle(view: caloriesBgView, color: kHexColor(0xFFCC9C))
|
||
|
distanceTipLabel.text = MultiLanguageKey.totalDistance.localized
|
||
|
countTipLabel.text = MultiLanguageKey.totalCount.localized
|
||
|
durationTipLabel.text = MultiLanguageKey.totalDuration.localized
|
||
|
caloriesTipLabel.text = MultiLanguageKey.totalCalories.localized
|
||
|
sportListLabel.text = MultiLanguageKey.sportList.localized
|
||
|
}
|
||
|
|
||
|
/// 刷新头视图
|
||
|
/// - Parameter sports: 运动数组
|
||
|
func refreshUI(sports: [SportModel]) {
|
||
|
var distance = 0
|
||
|
var calories: Float = 0
|
||
|
var duration = 0
|
||
|
sports.forEach { (sport) in
|
||
|
distance += sport.distance
|
||
|
calories += sport.calorie
|
||
|
duration += sport.duration
|
||
|
}
|
||
|
let metric = UserDefaultsManager.getUserInfo()?.metricUnit ?? 0
|
||
|
let distanceStr = metric == 0 ? String(format: "%0.2lf",CGFloat(distance) / 1000.0) : String(format: "%0.2lf", CGFloat(distance) / 1000.0 * 0.62137)
|
||
|
distanceValueLabel.text = distanceStr
|
||
|
distanceUnitLabel.text = metric == 0 ? "km" : "miles"
|
||
|
caloriesValueLabel.text = String(calories)
|
||
|
durationValueLabel.text = String(format: "%.1lf", Double(duration) / 3600)
|
||
|
countValueLabel.text = String(sports.count)
|
||
|
}
|
||
|
|
||
|
private func bgViewStyle(view: UIView, color: UIColor) {
|
||
|
view.layer.cornerRadius = 3
|
||
|
view.layer.borderWidth = 0.5
|
||
|
view.layer.borderColor = color.cgColor
|
||
|
}
|
||
|
|
||
|
}
|