LiveActivityIOBLabelView.swift 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // LiveActivityWidgetItems.swift
  3. // LiveActivityExtension
  4. //
  5. // Created by Cengiz Deniz on 17.10.24.
  6. //
  7. import Foundation
  8. import SwiftUI
  9. import WidgetKit
  10. struct LiveActivityIOBLabelView: View {
  11. var context: ActivityViewContext<LiveActivityAttributes>
  12. var additionalState: LiveActivityAttributes.ContentAdditionalState
  13. private var bolusFormatter: NumberFormatter {
  14. let formatter = NumberFormatter()
  15. formatter.numberStyle = .decimal
  16. formatter.maximumFractionDigits = 1
  17. formatter.decimalSeparator = "."
  18. return formatter
  19. }
  20. var body: some View {
  21. VStack(spacing: 2) {
  22. HStack {
  23. Text(
  24. bolusFormatter.string(from: additionalState.iob as NSNumber) ?? "--"
  25. )
  26. .fontWeight(.bold)
  27. .font(.title3)
  28. .foregroundStyle(context.isStale ? .secondary : .primary)
  29. .strikethrough(context.isStale, pattern: .solid, color: .red.opacity(0.6))
  30. Text("U")
  31. .font(.headline).fontWeight(.bold)
  32. .foregroundStyle(context.isStale ? .secondary : .primary)
  33. .strikethrough(context.isStale, pattern: .solid, color: .red.opacity(0.6))
  34. }
  35. Text("IOB").font(.subheadline).foregroundStyle(.primary)
  36. }
  37. }
  38. }